1 class Attachment < ActiveRecord::Base
4 has_attachment :processor => :rmagick
5 validates_as_attachment
6 after_attachment_saved do |record|
11 class SmallAttachment < Attachment
12 has_attachment :max_size => 1.kilobyte
15 class BigAttachment < Attachment
16 has_attachment :size => 1.megabyte..2.megabytes
19 class PdfAttachment < Attachment
20 has_attachment :content_type => 'pdf'
23 class DocAttachment < Attachment
24 has_attachment :content_type => %w(pdf doc txt)
27 class ImageAttachment < Attachment
28 has_attachment :content_type => :image, :resize_to => [50,50]
31 class ImageOrPdfAttachment < Attachment
32 has_attachment :content_type => ['pdf', :image], :resize_to => 'x50'
35 class ImageWithThumbsAttachment < Attachment
36 has_attachment :thumbnails => { :thumb => [50, 50], :geometry => 'x50' }, :resize_to => [55,55]
37 after_resize do |record, img|
38 # record.aspect_ratio = img.columns.to_f / img.rows.to_f
42 class FileAttachment < ActiveRecord::Base
43 has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files', :processor => :rmagick
44 validates_as_attachment
47 class FileAttachmentWithStringId < ActiveRecord::Base
48 set_table_name 'file_attachments_with_string_id'
49 has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files', :processor => :rmagick
50 validates_as_attachment
52 before_validation :auto_generate_id
53 before_save :auto_generate_id
59 self.id = "id_#{@@last_id}"
63 class FileAttachmentWithUuid < ActiveRecord::Base
64 set_table_name 'file_attachments_with_string_id'
65 has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files', :processor => :rmagick, :uuid_primary_key => true
66 validates_as_attachment
68 before_validation :auto_generate_id
69 before_save :auto_generate_id
75 self.id = "%0127dx" % @@last_id
79 class ImageFileAttachment < FileAttachment
80 has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
81 :content_type => :image, :resize_to => [50,50]
84 class ImageWithThumbsFileAttachment < FileAttachment
85 has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
86 :thumbnails => { :thumb => [50, 50], :geometry => 'x50' }, :resize_to => [55,55]
87 after_resize do |record, img|
88 # record.aspect_ratio = img.columns.to_f / img.rows.to_f
92 class ImageWithThumbsClassFileAttachment < FileAttachment
93 # use file_system_path to test backwards compatibility
94 has_attachment :file_system_path => 'vendor/plugins/attachment_fu/test/files',
95 :thumbnails => { :thumb => [50, 50] }, :resize_to => [55,55],
96 :thumbnail_class => 'ImageThumbnail'
99 class ImageThumbnail < FileAttachment
100 has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files/thumbnails'
104 class OrphanAttachment < ActiveRecord::Base
105 has_attachment :processor => :rmagick
106 validates_as_attachment
109 # no filename, no size, no content_type
110 class MinimalAttachment < ActiveRecord::Base
111 has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files', :processor => :rmagick
112 validates_as_attachment
120 class ImageScienceAttachment < ActiveRecord::Base
121 has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
122 :processor => :image_science, :thumbnails => { :thumb => [50, 51], :geometry => '31>' }, :resize_to => 55
124 rescue MissingSourceFile
126 puts "no ImageScience"
130 class CoreImageAttachment < ActiveRecord::Base
131 has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
132 :processor => :core_image, :thumbnails => { :thumb => [50, 51], :geometry => '31>' }, :resize_to => 55
134 rescue MissingSourceFile
140 class MiniMagickAttachment < ActiveRecord::Base
141 has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
142 :processor => :mini_magick, :thumbnails => { :thumb => [50, 51], :geometry => '31>' }, :resize_to => 55
144 rescue MissingSourceFile
146 puts "no Mini Magick"
150 class GD2Attachment < ActiveRecord::Base
151 has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
152 :processor => :gd2, :thumbnails => { :thumb => [50, 51], :geometry => '31>' }, :resize_to => 55
154 rescue MissingSourceFile
161 class MiniMagickAttachment < ActiveRecord::Base
162 has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
163 :processor => :mini_magick, :thumbnails => { :thumb => [50, 51], :geometry => '31>' }, :resize_to => 55
165 class ImageThumbnailCrop < MiniMagickAttachment
166 has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
167 :thumbnails => { :square => "50x50c", :vertical => "30x60c", :horizontal => "60x30c"}
169 # TODO this is a bad duplication, this method is in the MiniMagick Processor
170 def self.calculate_offset(image_width,image_height,image_aspect,thumb_width,thumb_height,thumb_aspect)
171 # only crop if image is not smaller in both dimensions
173 # special cases, image smaller in one dimension then thumbsize
174 if image_width < thumb_width
175 offset = (image_height / 2) - (thumb_height / 2)
176 command = "#{image_width}x#{thumb_height}+0+#{offset}"
177 elsif image_height < thumb_height
178 offset = (image_width / 2) - (thumb_width / 2)
179 command = "#{thumb_width}x#{image_height}+#{offset}+0"
181 # normal thumbnail generation
182 # calculate height and offset y, width is fixed
183 elsif (image_aspect <= thumb_aspect or image_width < thumb_width) and image_height > thumb_height
184 height = image_width / thumb_aspect
185 offset = (image_height / 2) - (height / 2)
186 command = "#{image_width}x#{height}+0+#{offset}"
187 # calculate width and offset x, height is fixed
189 width = image_height * thumb_aspect
190 offset = (image_width / 2) - (width / 2)
191 command = "#{width}x#{image_height}+#{offset}+0"
198 rescue MissingSourceFile
204 class S3Attachment < ActiveRecord::Base
205 has_attachment :storage => :s3, :processor => :rmagick, :s3_config_path => File.join(File.dirname(__FILE__), '../amazon_s3.yml')
206 validates_as_attachment
209 class CloudFilesAttachment < ActiveRecord::Base
210 has_attachment :storage => :cloud_files, :processor => :rmagick, :cloudfiles_config_path => File.join(File.dirname(__FILE__), '../rackspace_cloudfiles.yml')
211 validates_as_attachment
214 class S3WithPathPrefixAttachment < S3Attachment
215 has_attachment :storage => :s3, :path_prefix => 'some/custom/path/prefix', :processor => :rmagick
216 validates_as_attachment
219 class CloudFilesWithPathPrefixAttachment < CloudFilesAttachment
220 has_attachment :storage => :cloud_files, :path_prefix => 'some/custom/path/prefix', :processor => :rmagick
221 validates_as_attachment
225 puts "S3 error: #{$!}"