I just modified the file_column plugin a bit to do a quick check and make
sure the mime-type is image before it goes ahead and creates the thumbnails,
even if the :versions attribute is passed.
I added a is_image method to the RealUploadedFile class (file_column.rb):
def is_image?
@file_path = absolute_path
@content_type = get_content_type
if @content_type and @options[:mime_extensions][@content_type]
!@content_type.index(''image'').nil? and
@content_type.index(''image'') >= 0
end
end
And moved the "def get_content_type(fallback=nil) ..." from the
TempUploadedFile class into the RealUploadedFile class.
I then added a an additional check within the BaseUploadedFile
(magick_file_column.rb) needs_resize method for "is_image?":
def needs_resize?
@options[:magick] and just_uploaded? and is_image? and
(@options[:magick][:geometry] or @options[:magick][:versions])
end
Now when I have my model file which has:
file_column :path, :magick => { :versions => { "thumb"
=> "75x75",
"medium" => "640x480>" } }
If the file is not an image, it will just skip it, and go onto the next one.
The only time it needs to fail is if it really is a corrupt image and
it''s
unable to resize it.
Now all that needs to be done for the file_column list is have some logic
that uses the is_image check to see whether or not to use the image_tag
within the view to use the path of the generated from the
url_for_file_column, or use my own custom thumbnail for file types which are
not images such as a text file or mp3 file.
- Nathan
--------------------------------------------------------------
Nathaniel S. H. Brown Toll Free 1.877.4.INIMIT
Inimit Innovations Phone 604.724.6624
www.inimit.com Fax 604.444.9942