Search code examples
ruby-on-railsimagemagickpaperclipthumbnailseps

Have Paperclip make raster thumbnails of vector images


I'm working on a site that uses Paperclip to attach images to some records. Currently, all of the images are jpeg, and paperclip generates png thumbnails that appear in browser views.

We would like to add support for eps images as well. Without making any changes, uploading and downloading eps images already works, but the thumbnails are not generated. Paperclip does not log any errors, it just fails to generate a thumbnail.

has_attached_file :drawing, :styles => { :thumb => ["64x64#", :png] }, :convert_options => { :thumb => "-quality 75 -strip" }
validates_attachment :drawing

What needs to be added to generate thumbnails of eps files?


Solution

  • In my case it turned out to be a problem with the type spoofing detection. Paperclip seems to get confused when different sources of file type information disagree.

    The solution in my case was to create file named config/initializers/paperclip.rb with this content:

    Paperclip.options[:content_type_mappings] = {
      eps: "application/octet-stream"
    }
    

    I also tried editing the model to add validates_attachment_content_type and validates_attachment_file_name, neither of which had any noticeable effect.

    I would understand if Paperclip didn't trust that the attachment was an acceptable type and refused to attach it, I don't understand why it doesn't trust the type so it attaches the file but doesn't create the thumbnail.