How do I apply a drop shadow to thumbnails using imagemagick and paperclip?
imagemagick, paperclip, ruby, ruby-on-rails
Solution
After some trial and error and burying my head in the docs, I finally figured it out.
has_attached_file :image,
:styles => { :thumb => ["100x100#", :png] },
:convert_options => { :thumb => '\( +clone -background black -shadow 70x4+0+0 \) +swap -background none -layers merge +repage' }
- Make sure you have the latest version of ImageMagick installed.
- ["100x100#", :png] will convert the image to png so the drop shadow is transparent.
- Under convert options, :thumb will only apply the conversion to the :thumb style, use :all to apply the conversion to all your styles.
- Tweak "70x4+0+0" to get the shadow you want.
Problem
I would like to alter the processing of thumbnails in paperclip by having imagemagick apply a drop shadow to all the thumbnails. What I'm stuck on is the actual imagemagick command that would pull this little miracle off. Everything I've tried returns an incorrectly scaled drop shadow without the original image. ``` def transformation_command scale, crop = @current_geometry.transformation_to(@target_geometry, crop?) trans = "" trans << " -resize \"#{scale}\"" trans << " -crop \"#{crop}\" +repage" if crop # Apply Drop Shadow trans << " #{convert_options}" if convert_options? trans end ``` One I've tried... ``` def transformation_command scale, crop = @current_geometry.transformation_to(@target_geometry, crop?) trans = "" trans << " -resize \"#{scale}\"" trans << " -crop \"#{crop}\" +repage" if crop trans << " \( +clone -background black -shadow 60x5+10+10 \) +swap -background none -layers merge +repage" trans << " #{convert_options}" if convert_options? trans end ``` I'm completely new to imagemagick, any help would be greatly appreciated.