HtmlTo ๐ฅ
HtmlTo is a gem for Rails that allows you to generate images from an HTML file.๐ก
๐ Table of Contents
- Installation๐
- Usage ๐
- Advanced usage ๐งฐ
Installation
You need to have Chrome or Chromium installed ๐ ๏ธ And active-storage is required
Ubuntu:
sudo apt install -y chromium-browser
Debian:
apt-get install chromium chromium-l10n
add gem to your gemfile
gem 'html_to'
copy example serializer with
rails generate html_to:install
optional
for set path to chromium executable
#confg/initializers/html_to.rb
HtmlTo::Configuration.config do |config|
config.chromium_path = './path-to-executable'
end
to optimize attached images add gem 'image_processing'
Basic usage
Add to your model ๐
include HtmlTo
html_to HtmlToSerializer
Now after save your model new image will generated and attached to meta_image
in your model
Advanced usage
available options for customizations ๐งฐ
html_to HtmlTo::DummySerializer, image_name: :my_image, template: :image
option | descriotions | default |
---|---|---|
image_name |
name of attachment | meta_image |
template |
HTML template | circle |
synchronous |
Run image generation job not in background | false |
skip_auto_update |
skip auto update after save | false |
width |
width of image | 1200 |
height |
height of image | 630 |
template customization
there are two templates available circle
and image
for copy to your project:
rails generate html_to:copy_template
you can add your own template to app/views/html_to/*