Class: Paperclip::RoundCorners
- Inherits:
-
Thumbnail
- Object
- Thumbnail
- Paperclip::RoundCorners
- Defined in:
- lib/carousel/paperclip/round_corners.rb
Overview
Paperclip processor that uses ImageMagick to create rounded corners.
Derived from github.com/kerinin/paperclip-rounded-corners
Instance Method Summary collapse
-
#initialize(file, options = { }, attachment = nil) ⇒ RoundCorners
constructor
A new instance of RoundCorners.
- #make ⇒ Object
- #parse_opts(key) ⇒ Object
-
#round_corners(dst) ⇒ Paperclip::Attachment
Performs the ImageMagick corner-roundage.
-
#transformation ⇒ String
The ImageMagick command that rounds an image’s corners.
Constructor Details
#initialize(file, options = { }, attachment = nil) ⇒ RoundCorners
Returns a new instance of RoundCorners.
37 38 39 40 41 42 |
# File 'lib/carousel/paperclip/round_corners.rb', line 37 def initialize(file, = { }, = nil) super file, , @radius = [:border_radius] @process = @radius end |
Instance Method Details
#make ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/carousel/paperclip/round_corners.rb', line 45 def make @thumbnail = super if @process @width = Paperclip::Geometry.from_file(@thumbnail).width.to_i @height = Paperclip::Geometry.from_file(@thumbnail).height.to_i dst = Tempfile.new([@basename, @format].compact.join(".")) dst.binmode return round_corners(dst) else return @thumbnail end end |
#parse_opts(key) ⇒ Object
9 10 11 12 |
# File 'lib/carousel/paperclip/round_corners.rb', line 9 def parse_opts(key) opt = @options[:border_radius] opt.nil? ? nil : opt.to_i end |
#round_corners(dst) ⇒ Paperclip::Attachment
Performs the ImageMagick corner-roundage.
30 31 32 33 34 |
# File 'lib/carousel/paperclip/round_corners.rb', line 30 def round_corners(dst) command = "\"#{ File.(@thumbnail.path) }[0]\" #{ transformation } \"#{ File.(dst.path) }\"" Paperclip.run('convert', command) dst end |
#transformation ⇒ String
Returns The ImageMagick command that rounds an image’s corners.
16 17 18 19 20 21 22 23 |
# File 'lib/carousel/paperclip/round_corners.rb', line 16 def transformation trans = " \\( +clone -threshold -1 " trans << "-draw 'fill black polygon 0,0 0,#{@radius} #{@radius},0 fill white circle #{@radius},#{@radius} #{@radius},0' " trans << "\\( +clone -flip \\) -compose Multiply -composite " trans << "\\( +clone -flop \\) -compose Multiply -composite " trans << "\\) +matte -compose CopyOpacity -composite " trans end |