Created
March 31, 2015 03:03
-
-
Save satomixx/db01e8de92c2ec5ca86e to your computer and use it in GitHub Desktop.
[Rails 4.x] Linuxで、wkhtmltoimage(wkhtmltopdf) を利用して WebサイトのScreenshot を取る ref: http://qiita.com/tsumekoara/items/b683bcc3564fcef8d3af
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
namespace :screenshot do | |
desc "get screenshot from official_url and save tmp/screenshots/" | |
task :get => :environment do | |
quality = 100 | |
aspect_width = 4 | |
aspect_height = 3 # height : width = 4 : 3 | |
width = 1200 | |
height = width * 3 /4 | |
output_dir = "tmp/screenshots/" | |
items.each do |item| | |
output_file = "#{item.id}.jpg" | |
file_path = output_dir + output_file | |
command = "wkhtmltoimage --quality #{quality} --width #{width} --height #{height} #{url} #{file_path}" | |
IO.popen("#{command}") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo yum install -y openssl libX11 libXext libXext.so.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd /usr/local/src | |
$ wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm | |
$ sudo rpm -ivh wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm | |
error: Failed dependencies: | |
xorg-x11-fonts-Type1 is needed by wkhtmltox-1:0.12.2.1-1.x86_64 | |
xorg-x11-fonts-75dpi is needed by wkhtmltox-1:0.12.2.1-1.x86_64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo rpm -ivh ftp://rpmfind.net/linux/centos/6.6/os/x86_64/Packages/ttmkfdir-3.0.9-32.1.el6.x86_64.rpm | |
$ sudo rpm -ivh ftp://rpmfind.net/linux/centos/6.6/os/x86_64/Packages/xorg-x11-fonts-Type1-7.2-9.1.el6.noarch.rpm | |
$ sudo rpm -ivh ftp://rpmfind.net/linux/centos/6.6/os/x86_64/Packages/xorg-x11-fonts-75dpi-7.2-9.1.el6.noarch.rpm | |
$ sudo rpm -ivh wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# set font files at user home directory | |
$ mkdir ~/.fonts | |
$ cp IPAfont00302.zip ~/.fonts | |
$ cd ~/.fonts | |
$ unzip IPAfont00302.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# clear font cache | |
$ fc-cache -fv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# confirm installed font | |
$ fc-list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo cp ~/.fonts/*.ttf /usr/share/fonts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ wkhtmltoimage http://www.google.com hoge.jpg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment