问题
How do you create rounded corners with Paperclip? I have found this solution which creates rounded corners with paperclip using convert_options, but it does not work with Rails 3 and Paperclip 2.4.5. The generated convert command works only if I use the ImageMagick alpha parameter instead of the threshold paramter:
convert example.jpg \
\( +clone -alpha extract \
-draw 'fill black polygon 0,0 0,15 15,0 fill white circle 15,15 15,0' \
\( +clone -flip \) -compose Multiply -composite \
\( +clone -flop \) -compose Multiply -composite \
\) -alpha off -compose CopyOpacity -composite rounded_corners.png
which corresponds to
has_attached_file :avatar,
:styles => { :medium => ["918x483#", :png] },
:convert_options => {:medium => Proc.new{self.convert_options}}
def self.convert_options(px = 15)
trans = ""
trans << " \\( +clone -alpha extract "
trans << "-draw 'fill black polygon 0,0 0,#{px} #{px},0 fill white circle #{px},#{px} #{px},0' "
trans << "\\( +clone -flip \\) -compose Multiply -composite "
trans << "\\( +clone -flop \\) -compose Multiply -composite "
trans << "\\) +alpha off -compose CopyOpacity -composite "
end
This code snippet seems to produce the right convert command, but gives an "error processing the thumbnail for stream-xyz".
Command :: convert '/tmp/stream20120109-15817-1lju7p6-0.jpg[0]' -resize "918x"
-crop "918x483+0+105" +repage \( +clone -alpha extract -draw 'fill black polygon
0,0 0,15 15,0 fill white circle 15,15 15,0' \( +clone -flip \) -compose
Multiply -composite \( +clone -flop \) -compose Multiply -composite \) +alpha off
-compose CopyOpacity -composite '/tmp/stream20120109-15817-1lju7p6-....png'
[paperclip] An error was received while processing: #<Paperclip::PaperclipError:
There was an error processing the thumbnail for stream20120109-15817-1lju7p6-0>
回答1:
Finally I found it out, it was a simple typo. You have to use -alpha off
instead of +alpha off
, then the code above works without error. Sometimes a single sign (- instead of + or vice versa) makes the difference.
来源:https://stackoverflow.com/questions/8789820/rounded-corners-with-paperclip