Rounded corners with staples

How do you create rounded corners using Paperclip? I found this solution that creates rounded corners using paperclip using convert_options , but this does not work with Rails 3 and Paperclip 2.4.5. The generated conversion command only works if instead of the threshold parameter ImageMagick alpha instead

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

 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 piece of code seems to create the correct conversion command, but gives a " thumbnail processing error 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> 
+4
source share
1 answer

Finally, I realized it was a simple typo. You should use -alpha off instead of +alpha off , then the above code works without errors. Sometimes one sign matters (instead of + or vice versa).

+4
source

Source: https://habr.com/ru/post/1390049/


All Articles