added cropper processor

This commit is contained in:
nilsding 2014-12-29 14:51:52 +01:00
parent b61a631f15
commit 7aa954e212
2 changed files with 29 additions and 2 deletions

View File

@ -40,8 +40,9 @@ class User < ActiveRecord::Base
# validates :website, format: { with: WEBSITE_REGEX }
has_attached_file :profile_picture, styles: { medium: "256x256>", thumb: "80x80>" },
default_url: "/images/:style/no_avatar.png", use_timestamp: false
has_attached_file :profile_picture, styles: { large: "500x500#", medium: "256x256#", small: "80x80#" },
default_url: "/images/:style/no_avatar.png", use_timestamp: false,
processors: [:cropper]
validates_attachment_content_type :profile_picture, :content_type => /\Aimage\/.*\Z/
process_in_background :profile_picture
@ -155,4 +156,8 @@ class User < ActiveRecord::Base
def report_comment(report, content)
ModerationComment.create!(user: self, report: report, content: content)
end
def cropping?
!crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
end
end

View File

@ -0,0 +1,22 @@
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
x
else
super
end
end
def crop_command
target = @attachment.instance
if target.cropping?
['-crop', "'#{target.crop_w.to_i}x#{target.crop_h.to_i}+#{target.crop_x.to_i}+#{target.crop_y.to_i}'"]
end
end
end
end