【发布时间】:2013-10-07 15:26:50
【问题描述】:
使用 rmagick 查找图像的颜色..
img = Magick::Image.read("#{Rails.root}/public#{@design.photo.url(:profile)}").first
这是错误
unable to open image `/tmt/public/system/designs/photos/000/000/005/profile/5.jpg?1380037883': No such file or directory @ error/blob.c/OpenBlob/2646
该文件指向图像的确切位置,也许扩展名 (?1380037883) 将其丢弃,但我似乎无法解决问题。你们都知道是怎么回事吗?也许您已经使用 rgmagick 看到过类似的问题...这是我的 gemfile
gem 'rmagick', :require => 'RMagick'
如果我指向我的 app/assets/images 目录中的图像,它可以完美运行...只是当我使用变量查找用户上传的图像时出现此错误...
例如,这非常有效
img = Magick::Image.read("#{Rails.root}/app/assets/images/ruby.png").first
【问题讨论】:
-
只需使用
img = Magick::Image.read @design.photo.path(:profile)即可返回文件的完整路径 -
这不会返回任何东西
-
@design.photo.url(:profile)是回形针代码,对吧?如果是,那么@design.photo.path应该返回文件的完整路径。 -
是的回形针..好电话....最终起作用的是
img = Magick::Image.read(@design.photo.path).first
标签: ruby-on-rails ruby-on-rails-4 rmagick