0

我正在尝试从某些网站拍摄快照,但我在使用IMGKit时遇到了一些问题。

当我尝试在 Rails 任务上运行此代码时:

kit = IMGKit.new('http://www.adlibituradventures.com/')
kit = kit.to_img(:jpg) 
file_path = 'public/images/myimage.jpg'
file = kit.to_file(file_path)

我收到以下错误:

rake aborted!
undefined method `to_file' for #<String:0xa042bf8>
/home/paladini/Documents/Projetos/bittle/btc-stores/lib/tasks/crawl_usebitcoin.rake:269:in `get_image'
/home/paladini/Documents/Projetos/bittle/btc-stores/lib/tasks/crawl_usebitcoin.rake:113:in `block (3 levels) in <top (required)>'
/home/paladini/Documents/Projetos/bittle/btc-stores/lib/tasks/crawl_usebitcoin.rake:97:in `each'
/home/paladini/Documents/Projetos/bittle/btc-stores/lib/tasks/crawl_usebitcoin.rake:97:in `block (2 levels) in <top (required)>'
/home/paladini/Documents/Projetos/bittle/btc-stores/lib/tasks/crawl_usebitcoin.rake:43:in `block (2 levels) in <top (required)>'
/home/paladini/.rvm/gems/ruby-2.0.0-p353@btc-stores/bin/ruby_executable_hooks:15:in `eval'
/home/paladini/.rvm/gems/ruby-2.0.0-p353@btc-stores/bin/ruby_executable_hooks:15:in `<main>'

我的config/initializers/imgkit.rb

IMGKit.configure do |config|
  config.default_options = {
    :'use-xserver' => true
  }
end

如果我删除配置文件,然后执行我得到的 rake 任务:

rake aborted!
Command failed: /usr/local/bin/wkhtmltoimage --height 1000 --format jpg http://www.adlibituradventures.com/ -: Loading page (1/2)
QSslSocket: cannot resolve SSLv2_client_method               ] 10%
QSslSocket: cannot resolve SSLv2_server_method
No bp log location saved, using default.                     ] 36%
[000:000] Cpu: 6.37.5, x4, 2399Mhz, 2893MB
[000:000] Computer model: Not available
[000:000] Browser XEmbed support present: 1
[000:000] Browser toolkit is not Gtk2 (0).
[000:001] Using Xt toolkit
No bp log location saved, using default.
[000:000] Cpu: 6.37.5, x4, 2399Mhz, 2893MB
[000:000] Computer model: Not available
Rendering (2/2)                                                    
QPixmap: Cannot create a QPixmap when no GUI is being used   ] 25%
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPainter::begin: Paint device returned engine == 0, type: 2
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::translate: Painter not active
QPainter::setPen: Painter not active
QPainter::setBrush: Painter not active
QPainter::setWorldTransform: Painter not active
QPainter::setOpacity: Painter not active
QPainter::setFont: Painter not active
*** NSPlugin Viewer  *** *** NSPlugin Viewer  *** ERROR: rpc_end_sync called when not in sync!
ERROR: rpc_end_sync called when not in sync!

所以,我正在尝试使用这个配置文件,因为本教程告诉我们该--use-xserver标志解决了 QPixMap 的问题。但我不知道问题出在 IMGKit 还是 wkhtmltoimage 上。

在你问之前,我目前正在使用:

  • 导轨 4.0
  • 红宝石 2.0
  • Imgkit 1.3.10

拜托,有人可以帮助我吗?

4

1 回答 1

2

kit = kit.to_img(:jpg)

然后kit更改为字符串。

如果要保留kit,则更改变量名称。

于 2014-01-03T01:39:53.653 回答