I'm using dragonfly ~> 0.9.15
Given an image, I'm confused at how to use the convert method in dragonfly to crop a circular portion from the image with transparent background.
I am able to use a direct image magick command to run it from command line but the example command I found uses actual files and I'm unaware of how to get the file while dragonfly processes it on the fly.
Here's the actual command I took from a stack overflow question with imagemagick.
https://stackoverflow.com/a/999563/1664852
convert -size 200x200 xc:none -fill walter.jpg -draw "circle 100,100 100,1" circle_thumb.png
When I tried to achieve the same with dragonfly, this is the config:
require 'dragonfly/rails/images'
Dragonfly[:images].configure do |c|
c.job :crop_circle do
process :resize, "320x440"
encode :png
process :convert, '-virtual-pixel HorizontalTile -background transparent -draw "circle 400,400 400,1" -compose Copy_Opacity -composite'
end
end
I get the error no such image
when this runs in the server log.
How to configure the convert
function for this using the imagemagick commands?
Perhaps my solution can help others who are looking for a way to generate rounded images with the Dragonfly gem.
I was not able to find a solution readily available, but I managed to piece something together by taking a little bit here and there.
Turns out there is a very easy way to make rounded images with ImageMagick (6.8.9-1) using the vignette option which is explained here.
The following command line will generate an image with transparent background and the image rounded:
We can now get rounded images for profile pictures by adding a :rounded processor to the dragonfly.rb initializer as shown below:
Notice you might have to change the path for your convert command depending on which platform you are running on, I'm on Mac OS and ImageMagick is installed through Homebrew.
Now from any model having an image handled by Dragonfly you can call:
To return a rounded image which is 50px by 50px.