我在我的 Rails 项目中使用 IMGkit gem。我还安装wkhtmltoimage-binary
了 IMGkit 工作所必需的。IMGkit 和 wkhtmltoimage-binary 都是通过 gemfile 安装的。根据config/initializers/imgkit.rb
我有
IMGKit.configure do |config|
config.wkhtmltoimage = '/Users/Praveen/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/wkhtmltoimage-binary-0.12.2'
config.default_format = :png
end
在apps_controller.rb
def index
kit = IMGKit.new(html, :quality => 50)
# Get the image BLOB
img = kit.to_img
# Save to a file
file = kit.to_file('/path/to/save/file2.jpg')
# send to browser (Rails - use with #caches_page)
send_data(kit.to_img, :type => "image/jpeg", :disposition => 'inline')
结尾
运行时出现以下错误
虽然文件夹权限是 777。对此有任何帮助。提前致谢。