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 MiniMagick support to attachment_fu [Isacc]

git-svn-id: 
http://svn.techno-weenie.net/projects/plugins/attachment_fu@2744 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Mon Feb 19 00:02:13 -0800 2007
commit  adf7694cdbe014c032847551d27be9294d5e94bd
tree    73cbd032e2fda41acb08691e1af368457ef2c77c
parent  0d479b76070f3eaa20b455e847982966977ac9fd
...
1
2
3
 
4
5
6
...
1
2
 
3
4
5
6
0
@@ -1,6 +1,6 @@
0
 module Technoweenie # :nodoc:
0
   module AttachmentFu # :nodoc:
0
- @@default_processors = %w(ImageScience Rmagick)
0
+ @@default_processors = %w(ImageScience Rmagick MiniMagick)
0
     @@tempfile_path = File.join(RAILS_ROOT, 'tmp', 'attachment_fu')
0
     @@content_types = ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png']
0
     mattr_reader :content_types, :tempfile_path, :default_processors
...
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
...
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
@@ -25,28 +25,28 @@ module Technoweenie # :nodoc:
0
           end
0
         end
0
 
0
- protected
0
- def process_attachment_with_processing
0
- return unless process_attachment_without_processing
0
- with_image do |img|
0
- resize_image_or_thumbnail! img
0
- self.width = img.columns if respond_to?(:width)
0
- self.height = img.rows if respond_to?(:height)
0
- callback_with_args :after_resize, img
0
- end if image?
0
- end
0
-
0
- # Performs the actual resizing operation for a thumbnail
0
- def resize_image(img, size)
0
- size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Fixnum)
0
- if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
0
- size = [size, size] if size.is_a?(Fixnum)
0
- img.thumbnail!(*size)
0
- else
0
- img.change_geometry(size.to_s) { |cols, rows, image| image.resize!(cols, rows) }
0
- end
0
- self.temp_path = write_to_temp_file(img.to_blob)
0
+ protected
0
+ def process_attachment_with_processing
0
+ return unless process_attachment_without_processing
0
+ with_image do |img|
0
+ resize_image_or_thumbnail! img
0
+ self.width = img.columns if respond_to?(:width)
0
+ self.height = img.rows if respond_to?(:height)
0
+ callback_with_args :after_resize, img
0
+ end if image?
0
+ end
0
+
0
+ # Performs the actual resizing operation for a thumbnail
0
+ def resize_image(img, size)
0
+ size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Fixnum)
0
+ if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
0
+ size = [size, size] if size.is_a?(Fixnum)
0
+ img.thumbnail!(*size)
0
+ else
0
+ img.change_geometry(size.to_s) { |cols, rows, image| image.resize!(cols, rows) }
0
           end
0
+ self.temp_path = write_to_temp_file(img.to_blob)
0
+ end
0
       end
0
     end
0
   end
...
90
91
92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
94
95
...
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
0
@@ -90,6 +90,26 @@ begin
0
       :processor => :image_science, :thumbnails => { :thumb => [50, 51], :geometry => '31>' }, :resize_to => 55
0
   end
0
 rescue MissingSourceFile
0
+ puts $!.message
0
+ puts "no ImageScience"
0
+end
0
+
0
+begin
0
+ class MiniMagickAttachment < ActiveRecord::Base
0
+ has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
0
+ :processor => :mini_magick, :thumbnails => { :thumb => [50, 51], :geometry => '31>' }, :resize_to => 55
0
+ end
0
+rescue MissingSourceFile
0
+ puts $!.message
0
+ puts "no Mini Magick"
0
+end
0
+
0
+begin
0
+ class MiniMagickAttachment < ActiveRecord::Base
0
+ has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
0
+ :processor => :mini_magick, :thumbnails => { :thumb => [50, 51], :geometry => '31>' }, :resize_to => 55
0
+ end
0
+rescue MissingSourceFile
0
 end
0
 
0
 begin
...
34
35
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
38
39
...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
0
@@ -34,6 +34,28 @@ ActiveRecord::Schema.define(:version => 0) do
0
     t.column :type, :string
0
   end
0
 
0
+ create_table :mini_magick_attachments, :force => true do |t|
0
+ t.column :parent_id, :integer
0
+ t.column :thumbnail, :string
0
+ t.column :filename, :string, :limit => 255
0
+ t.column :content_type, :string, :limit => 255
0
+ t.column :size, :integer
0
+ t.column :width, :integer
0
+ t.column :height, :integer
0
+ t.column :type, :string
0
+ end
0
+
0
+ create_table :mini_magick_attachments, :force => true do |t|
0
+ t.column :parent_id, :integer
0
+ t.column :thumbnail, :string
0
+ t.column :filename, :string, :limit => 255
0
+ t.column :content_type, :string, :limit => 255
0
+ t.column :size, :integer
0
+ t.column :width, :integer
0
+ t.column :height, :integer
0
+ t.column :type, :string
0
+ end
0
+
0
   create_table :orphan_attachments, :force => true do |t|
0
     t.column :db_file_id, :integer
0
     t.column :filename, :string, :limit => 255

Comments

    No one has commented yet.