Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gem Paperclip::Errors::NotIdentifiedByImageMagickError

I'm trying to upload .pdf and .doc with paperclip.

Command :: file -b --mime '/var/folders/86/5tdcyh5171j6twqqkt49tq040000gn/T/d031fe0d3003c25aa6a9d1525403031a20140707-7537-6y9s83.pdf'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/86/5tdcyh5171j6twqqkt49tq040000gn/T/d031fe0d3003c25aa6a9d1525403031a20140707-7537-1ru9fns.pdf[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/86/5tdcyh5171j6twqqkt49tq040000gn/T/d031fe0d3003c25aa6a9d1525403031a20140707-7537-1ru9fns.pdf[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
   (0.2ms)  begin transaction
Command :: file -b --mime '/var/folders/86/5tdcyh5171j6twqqkt49tq040000gn/T/d031fe0d3003c25aa6a9d1525403031a20140707-7537-1b7261f.pdf'
   (0.2ms)  rollback transaction

1 Answers

Resizing images i.e. :styles => { :medium => "300x300>", :thumb => "345x215#" } requires imagemagick. Installing imagemagick should resolve the issue.

has_attached_file :media,
    :styles => {
      :medium => "300x300>",
      :thumb => "345x215#",
      :pdf_thumbnail => ["", :jpg]
    },
    :default_url => ActionController::Base.helpers.asset_path('branch-default.jpg')

validates :media, :attachment_content_type => { :content_type => ['image/png', 'image/jpg', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document']}

Also, specifying pdf_thumbnail for pdf uploads as it will generate a thumbnail image although I think this feature requires GhostScript: Here is an excerpt from the paperclip github page:

If you are dealing with pdf uploads or running the test suite, you'll also need GhostScript to be installed.

Another useful link for other content type thumbnails:

Custom thumbnails for file types with Paperclip

like image 145
Nicholas.V Avatar answered Dec 08 '25 07:12

Nicholas.V



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!