简体   繁体   中英

PaperClip gem Paperclip::Errors::NotIdentifiedByImageMagickError

There are numerous Stackoverflow questions regarding this, but after many hours, I've exhausted every angle I could think of, and still get the following error when I try to upload an image using the PaperClip gem (in tandem with PaperCrop, for cropping the image).

Paperclip::Errors::NotIdentifiedByImageMagickError - Paperclip::Errors::NotIdentifiedByImageMagickError:
paperclip (4.3.6) lib/paperclip/geometry_detector_factory.rb:10:in `make'
paperclip (4.3.6) lib/paperclip/geometry.rb:26:in `from_file'
papercrop (0.3.0) lib/papercrop/model_extension.rb:95:in `image_geometry'
papercrop (0.3.0) lib/papercrop/helpers.rb:45:in `cropbox'
app/views/users/_crop_photo_modal.html.haml:12:in `block in _app_views_users__crop_photo_modal_html_haml___1410212035753490924_70365684359680'

Here is what prints in the logs just prior to the error:

[AWS S3 200 0.554305 0 retries] head_object(:bucket_name=>"XXX-development-bucket-us",:key=>"profiles/profile_images/1/original/main_sized_small.png")

[AWS S3 200 0.049585 0 retries] head_object(:bucket_name=>"XXX-development-bucket-us",:key=>"profiles/profile_images/1/thumb/main_sized_small.png")

[AWS S3 200 0.053507 0 retries] head_object(:bucket_name=>"XXX-development-bucket-us",:key=>"profiles/profile_images/1/medium/main_sized_small.png")

[AWS S3 200 0.048024 0 retries] head_object(:bucket_name=>"XXX-development-bucket-us",:key=>"profiles/profile_images/1/large/main_sized_small.png")

Command :: PATH=/usr/local/bin/:$PATH; file -b --mime '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-t5fq8a.png'
Command :: PATH=/usr/local/bin/:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]' 2>/dev/null
Command :: PATH=/usr/local/bin/:$PATH; identify -format %m '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]'
Command :: PATH=/usr/local/bin/:$PATH; convert '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]' -auto-orient -resize "50x" -crop "50x50+0+0" +repage '/tmp/96994f01b3cacc5ddb9ed35b539d8c0420160601-82031-1n0cfvq'
Command :: PATH=/usr/local/bin/:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]' 2>/dev/null
Command :: PATH=/usr/local/bin/:$PATH; identify -format %m '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]'
Command :: PATH=/usr/local/bin/:$PATH; convert '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]' -auto-orient -resize "100x" -crop "100x100+0+0" +repage '/tmp/96994f01b3cacc5ddb9ed35b539d8c0420160601-82031-1fnck50'
Command :: PATH=/usr/local/bin/:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]' 2>/dev/null
Command :: PATH=/usr/local/bin/:$PATH; identify -format %m '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]'
Command :: PATH=/usr/local/bin/:$PATH; convert '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]' -auto-orient -resize "220x" -crop "220x220+0+0" +repage '/tmp/96994f01b3cacc5ddb9ed35b539d8c0420160601-82031-e3r9iy'
Command :: PATH=/usr/local/bin/:$PATH; file -b --mime '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-ub7nk7.png'
(0.4ms)  ROLLBACK
Command :: PATH=/usr/local/bin/:$PATH; identify -format '%wx%h,%[exif:orientation]' 'https://XXX-development-bucket-us.s3.amazonaws.com/profiles/profile_images/1/original/blake.png?1464811715[0]' 2>/dev/null

My environment:

  • paperclip v4.3.6
  • papercrop v0.3.0
  • aws-sdk v1.66.0
  • Rails 4.0.0
  • Ruby 2.0.0p643
  • Amazon S3 for file storage
  • OS-X Yosemite 10.10.5 (same error occurs on Heroku Linux server)

I have tried the following:

  1. Use aws-sdk version 2 or higher.
  2. Uninstall all imagemagick installs (I had 2 originally), and reinstall imagemagick with brew install imagemagick
  3. Downgrade PaperClip to 4.1.1
  4. Include :s3_credentials and :s3_permissions directly in the model, as follows:

    has_attached_file :profile_image, :styles => { :thumb => "50x50#", :medium => "100x100#", :large => "220x220#" }, :storage => :s3, :s3_credentials => {:bucket => "XXX-development-bucket-us", :access_key_id => "XXX", :secret_access_key => "XXX"}, :s3_permissions => "public-read", :default_url => '/images/:attachment/missing_:style.jpg' validates_attachment :profile_image, content_type: { content_type: ["image/jpg", "image/jpeg", "image/png"] } crop_attached_file :profile_image, :aspect => "1:1"

I thought it might be an s3 permissions problem, but the permissions on our development bucket should allow all access to the user identified by the keys.

I've also added...

Paperclip.options[:command_path] = "/usr/local/bin"

...to environments/development.rb.

I've verified ImageMagick is working on the commandline.

Any ideas what else to look at?

Yes, there are many exiting answers for this with different suggestions. But I tried out every possible solution for a day and arrived at the solution which fixed for me.

Ubuntu 12.04,Paperclip ~> '4.2'

Initially I was having ImageMagick 6.6.9-7 2016-06-01 Q16, updating this to ImageMagick 7.0.3-1 Q16 x86_64 2016-09-27 fixed it.

Note: Try installing the Imagemagick manually using wget http://www.imagemagick.org/download/ImageMagick.tar.gz

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM