Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- caches_page :small, :large
- def small
- render_promotion_thumbnail do |img|
- img.crop_resized!(100, 100, Magick::NorthWestGravity)
- end
- end
- def large
- render_promotion_thumbnail do |img|
- img.crop!(0, 0, 580, 190)
- end
- end
- private
- def render_promotion_thumbnail
- headers['Cache-Control'] = 'public'
- promotion = Promotion.find(params[:id])
- image_path = "#{RAILS_ROOT}/public/#{promotion.thumbnail}"
- image_path = "#{RAILS_ROOT}/public/images/promo-thumbnail-example.gif" unless File.exists?(image_path)
- img = Magick::Image.read(image_path).first
- yield(img)
- img.format = 'PNG'
- img.strip!
- send_data(img.to_blob, :type => 'image/png', :disposition => 'inline')
- GC.start
- end
Add Comment
Please, Sign In to add comment