Since there are not many code samples for IMGKit, I posted mine below.
I've studied the IMGKit documentation which says you can pass options to wkhtmltoimage via meta tags. So I created a page with the following meta tag which is not working:
<meta name="imgkit-height" content="420" />
There have been 127 views over two weeks without a comment or answer so I worked my tail off to get the answer. In addition, because there is so little out there on this gem I thought I'd add my whole process and code as a sample.
cat /proc/cpuinfoto find out my server CPU was Intel so installed the i386 version manually to /usr/local/bin. I changed the permissions on the wkhtmltoimage-i386 file to allow execution. Also, for IMGKit to recognize the file I had to rename the file, dropping off the "-i386".
def email_profile ... filename = current_user.username + "_" + cur_date + '.jpg' kit = IMGKit.new("https://www.myapp.com/applet/?auth_token=" + token) img = kit.to_img(:jpg) file = kit.to_file(Rails.root + "public/profile_images/" + filename) ... end
This view never gets rendered in a browser. It is exclusively for IMGKit / wkhtmltoimage to read. Note a different rails layout file is rendered:
class AppletController < ApplicationController def index render(:layout => "layouts/applet_lo") end end
The layout file has new meta tags that call wkhtmltoimage options to crop the image through the IMGKit gem. It still does not work. The author of the gem wrote back and said this feature is finicky. I am using minimagick to crop until this is fixed.
<!DOCTYPE html> <html> <head> <meta name="imgkit-crop-h" content="990"> <meta name="imgkit-crop-w" content="635"> </head> <body> <%= yield %> </body> </html>