public
Description: Treat an ActiveRecord model as a file attachment, storing its patch, size, content type, etc.
Homepage: http://weblog.techno-weenie.net
Clone URL: git://github.com/technoweenie/attachment_fu.git
Click here to lend your support to: attachment_fu and make a donation at www.pledgie.com !
attachment_fu / lib / attachment_fu / tasks / resize.rb
100644 24 lines (22 sloc) 0.863 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module AttachmentFu
  class Tasks
    class Resize < AttachmentFu::Pixels::Task
      def call(attachment, options)
        data = with_image(attachment) { |img| resize_image img, :size => options[:to], :to => options[:destination] }
        unless options[:skip_size]
          attachment.width = data.width if attachment.respond_to?(:width)
          attachment.height = data.height if attachment.respond_to?(:height)
        end
      end
    end
 
    class ImageSize < AttachmentFu::Pixels::Task
      def call(attachment, options)
        attachment.width, attachment.height = with_image(attachment) { |img| get_image_size(img) }
      end
    end
  end
end
 
# task :resize, :with => :mojo_magic, :to => '50x50'
#
AttachmentFu.create_task :resize, AttachmentFu::Tasks::Resize
AttachmentFu.create_task :get_image_size, AttachmentFu::Tasks::ImageSize