Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- before_update :crop_photo
- has_attached_file :photo,
- :styles => { :original => Proc.new { |u| u.crop_photo? ? '' : '100%x100%' },
- :inbox => '20x20!' },
- :convert_options => { :original => Proc.new { |u| u.crop_photo? ? "-crop #{u.photo_crop_width}x#{u.photo_crop_height}+#{u.photo_crop_left}+#{u.photo_crop_top} +repage" : '' } }
- [ :photo_crop_width, :photo_crop_height, :photo_crop_top, :photo_crop_left ].each do |attr_name|
- attr_writer attr_name
- attr_accessible attr_name
- define_method(attr_name) do
- instance_variable_get("@#{attr_name}").to_i
- end
- end
- def crop_photo?
- !(photo.nil? || photo.dirty? || [ photo_crop_width, photo_crop_height, photo_crop_top, photo_crop_left ].all?(&:zero?))
- end
- def crop_photo
- photo.reprocess! if crop_photo?
- end
Add Comment
Please, Sign In to add comment