Paperclip before_process For Your Habitual Pornographic Needs

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:

  1. Paperclip Resized Image Details In to_xml
  2. Inherited_resources fondles swfupload and you didn’t even know it
  3. Disabling Paperclip asset timestamp keeps you from committing genocide
  4. RubyOnRails Seed_fu and Paperclip woes
  • tankow
    Sweet...been wondering how to do this and will expand it to process video as well
  • theRemix
    wao!

    thanks, i needed this like 3 months ago when you were moving and barely had internets.
blog comments powered by Disqus