0

I have to create 300px widht thumbnails if the file is a picture ('image/jpeg', 'image/png', 'image/gif') and no thumbnails if the file has an other extension. I'm using Paperclip for file-upload (it's working great without the conditions...).

:file is the uploaded file and if it is an image, Paperclip should create a medium version of it.

class Paperplanes < ActiveRecord::Base
   if validates_attachment_content_type :file, :content_type => ['image/jpeg', 'image/png', 'image/gif']
      has_attached_file :file, :styles => { :medium => "x300>" }
   else
      has_attached_file :file
   end
end

But this doesn't seem to work. Hope you guys can find a solution. THX!

nenebale
  • 15
  • 3

1 Answers1

0

If it isn't an image, thumbnail creation should fail. If whiny isn't true, that should be the end of it. (Mostly; you'd need to check for thumbnail presence then, as per this answer.)

If you want to completely control the process, you could either open up the default Thumbnail processor to add/change its normal options/handling, or use it as a guide to create your own processor (see the "Post Processing" section on Paperclip's github page).

You could also play some games with a lambda style, perhaps creating a default "non-image" thumbnail for non-image files.

Community
  • 1
  • 1
Dave Newton
  • 158,873
  • 26
  • 254
  • 302