4
如何用回形針創建圓角?我發現這個解決方案創建了rounded corners with paperclip using convert_options,但它不適用於Rails 3和Paperclip 2.4.5。生成的唯一的,如果我使用ImageMagick alpha parameter,而不是門檻放慢參數轉換命令作品:帶回形針的圓角
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
相當於
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
該代碼段似乎產生正確的轉換命令,而是給出了一個「處理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>
感謝您回來讓我們知道解決方案。它幫助了我。 – peterept 2015-03-10 13:07:19
它的工作,但只是與PNG,這是可能與JPG? – dtelaroli 2017-02-15 13:26:36