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