Created
December 4, 2011 19:46
-
-
Save cmilfont/1431105 to your computer and use it in GitHub Desktop.
Thumbnail com crop circular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validates_attachment_presence :avatar | |
validates_attachment_content_type :avatar, :content_type => ["image/png", "image/jpeg", "image/jpg"] | |
validates_attachment_size :avatar, :less_than => 10.megabytes | |
has_attached_file :avatar, | |
:styles => { | |
:medium => "446x310>", | |
#importante definir png como formato do thumb senão ele não aplica o crop se for jpg | |
:thumb => ["100x105#", :png], | |
:dashboard => "150X200>" }, | |
:convert_options => { | |
:thumb => Proc.new{ self.convert_options } | |
} | |
#http://loo.no/2009/08/09/rounded-corners-with-paperclip | |
def self.convert_options | |
trans = "" | |
px = 50 | |
trans << " \\( +clone -threshold -1 " | |
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 << "\\) +matte -compose CopyOpacity -composite " | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment