Guest User

Untitled

a guest
Apr 26th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. caches_page :small, :large
  2.  
  3. def small
  4. render_promotion_thumbnail do |img|
  5. img.crop_resized!(100, 100, Magick::NorthWestGravity)
  6. end
  7. end
  8.  
  9. def large
  10. render_promotion_thumbnail do |img|
  11. img.crop!(0, 0, 580, 190)
  12. end
  13. end
  14.  
  15. private
  16.  
  17. def render_promotion_thumbnail
  18. headers['Cache-Control'] = 'public'
  19.  
  20. promotion = Promotion.find(params[:id])
  21. image_path = "#{RAILS_ROOT}/public/#{promotion.thumbnail}"
  22. image_path = "#{RAILS_ROOT}/public/images/promo-thumbnail-example.gif" unless File.exists?(image_path)
  23. img = Magick::Image.read(image_path).first
  24.  
  25. yield(img)
  26.  
  27. img.format = 'PNG'
  28. img.strip!
  29.  
  30. send_data(img.to_blob, :type => 'image/png', :disposition => 'inline')
  31.  
  32. GC.start
  33. end
Add Comment
Please, Sign In to add comment