Retrospring/lib/paperclip_processors/cropper.rb

27 lines
772 B
Ruby
Raw Normal View History

2014-12-29 05:51:52 -08:00
module Paperclip
class Cropper < Thumbnail
def transformation_command
if crop_command
x = super
i = x.index '-crop'
2.times { x.delete_at i } if i
2014-12-29 05:59:12 -08:00
crop_command + x
2014-12-29 05:51:52 -08:00
else
super
end
end
def crop_command
target = @attachment.instance
if target.cropping?
2015-05-09 17:57:18 -07:00
case @attachment.name
when :profile_picture
2015-07-19 15:46:31 -07:00
['-auto-orient', '-strip', '+repage', '-crop', "'#{target.crop_w.to_i}x#{target.crop_h.to_i}+#{target.crop_x.to_i}+#{target.crop_y.to_i}'"]
2015-05-09 17:57:18 -07:00
when :profile_header
2015-07-19 15:46:31 -07:00
['-auto-orient', '-strip', '+repage', '-crop', "'#{target.crop_h_w.to_i}x#{target.crop_h_h.to_i}+#{target.crop_h_x.to_i}+#{target.crop_h_y.to_i}'"]
2015-05-09 17:57:18 -07:00
end
2014-12-29 05:51:52 -08:00
end
end
end
end