Reputation: 1088
I'm using Dragonfly and would like to have a default image that resizes in the same way present thumbnails do.
I currently have the following code, but when Dragonfly uses the fetch_file method, it tries to process a thumbnail but the resulting URL is a dead link.
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"
I can't find much help on line for this, so any hints are most appreciated! Thanks!
Upvotes: 4
Views: 2758
Reputation: 13428
You can set a default image with your model accessor:
class Photo
dragonfly_accessor :image do
default 'public/images/default.png'
end
end
See the docs: http://markevans.github.io/dragonfly/models/#default-content
Upvotes: 3
Reputation: 1088
I managed to get this fixed by first adding the config code provided by Mark.
I was then getting this error in my logs:
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.
Since ImageMagick can't seem to use a path name relative to the project, I had to assign an absolute path. Like this:
img = Dragonfly[:images].fetch_file(File.join(Rails.root, 'public', 'toekomst', 'images', 'speech-bubble.png'))
Upvotes: 1
Reputation: 311
you need to set the config value 'allow_fetch_file' to true - requesting over the server using fetch_file is turned off by default for security (this isn't documented particularly except for here: http://markevans.github.com/dragonfly/Dragonfly/Server.html If you do this, however, you should probably turn on 'protect_from_dos_attacks' to true, again for security:
Dragonfly[:images].configure do |c|
# ...
c.allow_fetch_file = true
c.protect_from_dos_attacks = true
c.secret = "some secret here..."
end
Hope that helps
Upvotes: 6