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 !
add mojo_magick support
rick (author)
Wed Apr 23 01:02:54 -0700 2008
commit  748af7ea77c243d8520cd3351035710638821c79
tree    37f707dffe47766c11d994c290c15ea96dd78b9c
parent  47447569571d5d17e337215c5be42cb35547b181
...
23
24
25
26
 
27
28
29
...
33
34
35
36
 
37
38
 
 
39
 
40
41
42
...
23
24
25
 
26
27
28
29
...
33
34
35
 
36
37
 
38
39
40
41
42
43
44
0
@@ -23,7 +23,7 @@ module AttachmentFu
0
         # PDI a simple configurable order
0
         # task :resize, :with => [:core_image, :gd, :image_science, :rmagick]
0
         #
0
- options[:with] ||= :core_image
0
+ options[:with] ||= :mojo_magick
0
         new options[:with], attachment.full_filename do
0
           data = with_image { |img| resize_image img, :size => options[:to] }
0
           attachment.width = data.width if attachment.respond_to?(:width)
0
@@ -33,10 +33,12 @@ module AttachmentFu
0
     end
0
 
0
     class Image
0
- attr_accessor :width, :height, :size
0
+ attr_accessor :filename, :width, :height, :size
0
       
0
- def initialize
0
+ def initialize(filename = nil)
0
+ @filename = filename
0
         yield self if block_given?
0
+ @size = File.size(filename) if filename && File.exist?(filename)
0
       end
0
     end
0
   end
...
1
2
 
3
4
5
...
31
32
33
34
 
35
36
37
38
39
40
41
42
...
 
1
2
3
4
5
...
31
32
33
 
34
35
36
37
38
 
39
40
41
0
@@ -1,5 +1,5 @@
0
-require 'attachment_fu/geometry'
0
 require 'red_artisan/core_image/processor'
0
+require 'attachment_fu/geometry'
0
 
0
 module AttachmentFu # :nodoc:
0
   class Pixels
0
@@ -31,12 +31,11 @@ module AttachmentFu # :nodoc:
0
         end
0
         
0
         destination = options[:to] || @file
0
- AttachmentFu::Pixels::Image.new do |img|
0
+ AttachmentFu::Pixels::Image.new destination do |img|
0
           processor.render do |result|
0
             img.width = result.extent.size.width
0
             img.height = result.extent.size.height
0
             result.save destination, OSX::NSJPEGFileType
0
- img.size = File.size(destination)
0
           end
0
         end
0
       end
...
23
24
25
26
 
27
28
29
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
32
33
...
23
24
25
 
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
0
@@ -23,11 +23,30 @@ describe AttachmentFu::Pixels::CoreImage do
0
       end
0
     end
0
     
0
- it "resizes image" do
0
+ it "resizes image with geometry string" do
0
       @pixels.with_image do |image|
0
         data = @pixels.resize_image image, :size => '40x40', :to => File.join(AttachmentFu.root_path, 'resized.jpg')
0
         data.width.should == 40
0
         data.height.should == 38
0
+ data.size.should satisfy { |s| s > 0 }
0
+ end
0
+ end
0
+
0
+ it "resizes image with integer" do
0
+ @pixels.with_image do |image|
0
+ data = @pixels.resize_image image, :size => 40, :to => File.join(AttachmentFu.root_path, 'resized.jpg')
0
+ data.width.should == 40
0
+ data.height.should == 37
0
+ data.size.should satisfy { |s| s > 0 }
0
+ end
0
+ end
0
+
0
+ it "resizes image with array" do
0
+ @pixels.with_image do |image|
0
+ data = @pixels.resize_image image, :size => [40, 40], :to => File.join(AttachmentFu.root_path, 'resized.jpg')
0
+ data.width.should == 40
0
+ data.height.should == 40
0
+ data.size.should satisfy { |s| s > 0 }
0
       end
0
     end
0
   end

Comments

    No one has commented yet.