我正在使用 imagekit 和 wkhtmltoimage 将 html 转换为图像。在我的本地服务器上,我使用的是 ubuntu 14.10,它工作正常。但是实时服务器是 centos 6,当我将代码移动到实时服务器时,它显示以下 libjpeg 错误:
error while loading shared libraries: libjpeg.so.8: cannot open shared object file: No such file or directory
完整的错误代码:
Command failed: /root/.rbenv/versions/2.1.2/bin/wkhtmltoimage --height 470 --width 350 --transparent --quality 60 --format png - -: /root/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/wkhtmltoimage-binary-0.12.1/libexec/wkhtmltoimage-amd64: error while loading shared libraries: libjpeg.so.8: cannot open shared object file: No such file or directory
这是我在控制器中创建图像的代码:
html_content = "<div style='margin:-8px -2px 15px -8px;background:none repeat scroll 0 0 #{temp_params['color']}; direction: #{temp_params['direction']}; font-size: 22px;color: #fff;font-family:arial;line-height: 30px;padding: 15px; height: 470px;width:350px;border-radius: 4px;position:relative;text-align:center;display:table;'><div style='display:table-cell;vertical-align:middle;word-break:break-all;'>#{temp_params['text']}</div></div>"
file = Tempfile.new(["quote", '.png'], 'tmp', :encoding => 'ascii-8bit')
img = IMGKit.new(html_content, height: 470, width: 350, transparent: true, quality:60, :layout => false)
file.write(img.to_img(:png))
temp.attachment = file
file.unlink
temp.save
我检查了各种链接上提供的解决方案,但没有一个有效。