我使用蜻蜓,并希望有一个默认的图像,大小大小与现在的缩略图一样。
我现在有以下代码,但是当蜻蜓使用fetch_file方法时,它尝试处理一个缩略图,但是得到的URL是一个死链接。
if listing.image
image = listing.image.jpg
else
image = Dragonfly[:images].fetch_file('/toekomst/images/speech-bubble.png')
end
image_tag image.jpg.thumb(size).url, :class => "framed"我在网上找不到多少帮助,所以任何提示都是非常感谢的!谢谢!
发布于 2011-08-19 08:43:32
通过首先添加Mark提供的配置代码,我成功地解决了这个问题。
然后,我在日志中得到了这个错误:
identify: unable to open image `/toekomst/images/speech-bubble.png': No such file or directory @ error/blob.c/OpenBlob/2584.
identify: unable to open file `/toekomst/images/speech-bubble.png' @ error/png.c/ReadPNGImage/3079.
[2011-08-19 10:33:51] ERROR Dragonfly::FunctionManager::UnableToHandle: None of the functions registered with #<Dragonfly::Encoder:0x00000100d66d88> were able to deal with the method call encode(#<Dragonfly::TempObject:0x00000104aa2800 pathname=#<Pathname:/toekomst/images/speech-bubble.png> >,:jpg). You may need to register one that can.由于ImageMagick似乎不能使用相对于项目的路径名称,所以我不得不指定一个绝对路径。如下所示:
img = Dragonfly[:images].fetch_file(File.join(Rails.root, 'public', 'toekomst', 'images', 'speech-bubble.png'))发布于 2011-08-18 22:49:32
您需要将配置值'allow_fetch_file‘设置为true --默认情况下,为了安全起见,关闭对服务器使用fetch_file的请求(除了这里:http://markevans.github.com/dragonfly/Dragonfly/Server.html之外,没有特别说明:http://markevans.github.com/dragonfly/Dragonfly/Server.html,但是如果这样做,您可能应该将'protect_from_dos_attacks’打开为true,同样也是为了安全性:
Dragonfly[:images].configure do |c|
# ...
c.allow_fetch_file = true
c.protect_from_dos_attacks = true
c.secret = "some secret here..."
end希望这有帮助
发布于 2014-10-29 16:24:42
可以使用模型访问器设置默认映像:
class Photo
dragonfly_accessor :image do
default 'public/images/default.png'
end
end见docs:http://markevans.github.io/dragonfly/models/#default-content
https://stackoverflow.com/questions/7096597
复制相似问题