Ok, so say you built yourself a handy dandy little webapp for organizing all the porno pics you ripped from google image search, you know, since you live alone in your parents basement and all. Suddenly, it strikes you, “I should move up to porno movies now, but I want to keep my images”. You’re going to fail without this piece of advice. Paperclip allows for you to implement your own processor, but its default processor is for generating thumbnails with ImageMagick. Low and behold, hooks! That’s right, with the before_post_process hook you can control whether or not to process.
1 2 3 4 5 | has_attached_file :source, :styles => { :thumb => "100x100#" } before_post_process :is_image? def is_image? !(source_content_type =~ /^image/).nil? end |
Throw this in your model, but pay attention at the source_content_type in is_image?, it should be named according to your attachment name. You could use mimetype_fu, but there really is no point considering all the content_types for images, that I know of, begin with ‘image/*’. Now, when you upload content, you can upload anything, but only images will be resized. Sweet spankin!
Related posts: