Guest User

Untitled

a guest
Apr 26th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. before_update :crop_photo
  2.  
  3. has_attached_file :photo,
  4. :styles => { :original => Proc.new { |u| u.crop_photo? ? '' : '100%x100%' },
  5. :inbox => '20x20!' },
  6. :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" : '' } }
  7.  
  8. [ :photo_crop_width, :photo_crop_height, :photo_crop_top, :photo_crop_left ].each do |attr_name|
  9. attr_writer attr_name
  10. attr_accessible attr_name
  11. define_method(attr_name) do
  12. instance_variable_get("@#{attr_name}").to_i
  13. end
  14. end
  15.  
  16. def crop_photo?
  17. !(photo.nil? || photo.dirty? || [ photo_crop_width, photo_crop_height, photo_crop_top, photo_crop_left ].all?(&:zero?))
  18. end
  19.  
  20. def crop_photo
  21. photo.reprocess! if crop_photo?
  22. end
Add Comment
Please, Sign In to add comment