PaperClip gem Paperclip::Errors::NotIdentifiedByImageMagickError - ruby-on-rails

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:
Use aws-sdk version 2 or higher.
Uninstall all imagemagick installs (I had 2 originally), and reinstall imagemagick with brew install imagemagick
Downgrade PaperClip to 4.1.1
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

Related

Store thumb image to specific directory in paperclip gem

Here is the code
has_attached_file :image,
:path => ":rails_root/public/images/:id/:filename",
:url => "/images/:id/:filename",
:styles => { :small => "300x168>", :large => "1000x560>" }
Here is my console log
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; file -b --mime '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-1gg7ekt.png'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]' 2>/dev/null
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; identify -format %m '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; convert '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]' -auto-orient -resize "300x168>" '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm20150617-13080-8q41x9'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; file -b --mime '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm20150617-13080-8q41x9'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]' 2>/dev/null
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; identify -format %m '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; convert '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]' -auto-orient -resize "1000x560>" '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm20150617-13080-q57vxf'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; file -b --mime '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm20150617-13080-q57vxf'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; file -b --mime '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-1o3we23.png'
I need to store small,large and original image to my project public directory but it store only the original
You can use :styles of paperclip gem in your model. Like,
has_attached_file :photo,
:styles => {
:thumb=> "100x100#",
:small => "150x150>",
:medium => "300x300>",
:large => "400x400>" }
And your photo url is going to be as follows : /public/photos/(event#)/(size_name)/image_name
And you have to install ImageMagick and rb-magick ports to get this going.
For more details you can refer this links Upload Image using Paperclip gem
Check that your image magick installed correctly or not as resizing is depends on image magick.
to refresh all of your defined styles in one go (:thumb, :small, :medium from the above example)
rake paperclip:refresh CLASS=Modelname
and to refresh only missing styles:
a list of styles will be defined or updated in a file “/public/system/paperclip_attachments.yml”
rake paperclip:refresh:missing_styles
Additionally, if you want to only reprocess a single style you may do so like:
users_to_reprocess.each do |user|
user.image.reprocess! :small
end

Paperclip - Save image dimensions to database from already uploaded images to S3

I have big troubles...
I have uploaded around 500 images to S3 via my Rails app in a couple of different sizes. Now I realize that I need to store those images dimensions to my database. My approach to do this is with this migration:
class AddImageDimensionsToImages < ActiveRecord::Migration
def change
# add image columns
add_column :images, :small_width, :integer
add_column :images, :small_height, :integer
add_column :images, :medium_width, :integer
add_column :images, :medium_height, :integer
add_column :images, :large_width, :integer
add_column :images, :large_height, :integer
add_column :images, :original_width, :integer
add_column :images, :original_height, :integer
# loop all images
Image.all.each do |image|
# get sizes
geo_small = Paperclip::Geometry.from_file(image.image.to_file(:small))
geo_medium = Paperclip::Geometry.from_file(image.image.to_file(:medium))
geo_large = Paperclip::Geometry.from_file(image.image.to_file(:large))
geo_original = Paperclip::Geometry.from_file(image.image.to_file(:original))
# set sizes
image.small_width = geo_small.width if geo_small
image.small_height = geo_small.height if geo_small
image.medium_width = geo_medium.width if geo_medium
image.medium_height = geo_medium.height if geo_medium
image.large_width = geo_large.width if geo_large
image.large_height = geo_large.height if geo_large
image.original_width = geo_original.width if geo_original
image.original_height = geo_original.height if geo_original
# save image
image.save
end
end
end
When I run this migration it goes like this:
...
-- add_column(:images, :small_width, :integer)
-> 2.0866s
-- add_column(:images, :small_height, :integer)
-> 0.0092s
-- add_column(:images, :medium_width, :integer)
-> 0.0073s
...
Command :: identify -format %wx%h '/app/tmp/HayUnFinal_1620120408-4-qpzyym.jpg[0]'
[AWS S3 200 0.106467] get_object(:bucket_name=>"aa",:key=>"original/34/HayUnFinal_16.jpg")
Command :: identify -format %wx%h '/app/tmp/HayUnFinal_1620120408-4-1vqo71y.jpg[0]'
[paperclip] Saving attachments.
[AWS S3 200 0.152898] get_object(:bucket_name=>"aa",:key=>"small/64/Portrait_2.jpg")
Command :: identify -format %wx%h '/app/tmp/Portrait_220120408-4-i1ohlr.jpg[0]'
[AWS S3 200 0.055378] get_object(:bucket_name=>"aa",:key=>"medium/64/Portrait_2.jpg")
Command :: identify -format %wx%h '/app/tmp/Portrait_220120408-4-viizzf.jpg[0]'
[AWS S3 200 0.079235] get_object(:bucket_name=>"aa",:key=>"large/64/Portrait_2.jpg")
Command :: identify -format %wx%h '/app/tmp/Portrait_220120408-4-1d2u00o.jpg[0]'
[AWS S3 200 0.066724] get_object(:bucket_name=>"aa",:key=>"original/64/Portrait_2.jpg")
Command :: identify -format %wx%h '/app/tmp/Portrait_220120408-4-jq9wmg.jpg[0]'
[paperclip] Saving attachments.
[AWS S3 200 0.104891] get_object(:bucket_name=>"aa",:key=>"small/58/Bansah_24.jpg")
Command :: identify -format %wx%h '/app/tmp/Bansah_2420120408-4-an2mpt.jpg[0]'
[AWS S3 200 0.064148] get_object(:bucket_name=>"aa",:key=>"medium/58/Bansah_24.jpg")
Command :: identify -format %wx%h '/app/tmp/Bansah_2420120408-4-tzmnup.jpg[0]'
[AWS S3 200 0.051090] get_object(:bucket_name=>"aa",:key=>"large/58/Bansah_24.jpg")
Command :: identify -format %wx%h '/app/tmp/Bansah_2420120408-4-1pa0rxh.jpg[0]'
[AWS S3 200 0.063531] get_object(:bucket_name=>"aa",:key=>"original/58/Bansah_24.jpg")
Command :: identify -format %wx%h '/app/tmp/Bansah_2420120408-4-kogk2g.jpg[0]'
[paperclip] Saving attachments.
rake aborted!
An error has occurred, this and all later migrations canceled:
can't convert nil into String
rake aborted! It seems to work for a couple of images, but then the migration fails. I can't really figure out where that nil comes from, and how I can prevent it. Can anyone help me with this?
Bonus question: Is this a retared way to approach the task of saving image dimensions of already uploaded images?
Thanks a lot in advance!
Some image rows in the database had null image values. A check like this made the trick:
Image.all.each do |image|
# check that we have an image
if image.image_file_size
...
end
end

paperclip not displaying medium or thumb in rails 3.1

I'm using paperclip with Rails 3.1. When I add the image, it shows me the original size but doesn't show me thumb or medium sizes:
Here is what I have in my view:
<%= image_tag #image.avatar.url(:thumb) %>
<%= image_tag #image.avatar.url(:medium) %>
image.rb
has_attached_file :avatar, :whiny => false, :styles => { :medium => "300x300>", :thumb => "100x100>" }
UPDATE:
Here is the error I'm getting with :whiny => true
Command :: identify -format %wx%h '/var/folders/54/txjcl9l130j6dq73r37hf2c00000gn/T/stream20111213-9180-1plu1me.png[0]'
[paperclip] An error was received while processing: #
Command :: identify -format %wx%h '/var/folders/54/txjcl9l130j6dq73r37hf2c00000gn/T/stream20111213-9180-1plu1me.png[0]'
[paperclip] An error was received while processing: #
Rendered images/new.html.erb within layouts/application (4.0ms)
First, make sure that Image Magick is installed.
To see if its installed properly, go to a terminal session and type which convert. You should see a path to the executable.
Once that is done, you may need to add the path to your environment.rb file. For example, my convert is located at /usr/local/bin/convert. Now I've seen two different ways of setting your path for paperclip, try one or the other and see what works.
# specifically set the paperclip path
Paperclip.options[:command_path] = '/usr/local/bin'
# set the path in general, might not be necessary
ENV['PATH'] = '/usr/local/bin:' + ENV['PATH']

rails + paperclip + plupload

Hi i'm using paperclip and plupload like in this tutorial:
http://www.theroamingcoder.com/node/50
It works.
But if i try to set thumbnails with paperclip like:
has_attached_file :data,
:styles => { :medium => "558x418>", :thumb => "60x82>" }
It doesn't work.
I receive this error:
[paperclip] identify -format %wx%h '/tmp/stream20110209-26212-1l2obtp-0.png[0]' 2>/dev/null
[paperclip] convert '/tmp/stream20110209-26212-1l2obtp-0.png[0]' -resize "558x418>" '/tmp/stream20110209-26212-1l2obtp-020110209-26212-cl5lbg-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110209-26212-1l2obtp-0>
[paperclip] identify -format %wx%h '/tmp/stream20110209-26212-1l2obtp-0.png[0]' 2>/dev/null
[paperclip] convert '/tmp/stream20110209-26212-1l2obtp-0.png[0]' -resize "60x82>" '/tmp/stream20110209-26212-1l2obtp-020110209-26212-1m6qvkj-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110209-26212-1l2obtp-0
How can i solve it?
thanks
It looks like you don't have Imagemagick installed!
http://www.imagemagick.org/script/index.php
If I am wrong try this
has_attached_file :data, :styles => { :medium => ["558x418>", :png], :thumb => ["60x82>", :png] }
I had to disable chunks in plupload

rails routes using picnik with paperclip

I've been trying to get picnik to work with paperclip so I can resize and touch up images, however have had some difficulty so far.
I'm a bit confused over the routing, as I get an error:
Started POST "/products/3/photos/4" for 208.88.21.57 at Fri Dec 10 14:44:59 -0800 2010
ActionController::RoutingError (No route matches "/products/3/photos/4"):
This is when I try to pass the file back from picnik, however simply updating the image title on the same record using the exact same path seems to work fine and uses the exact same routing as above:
Started POST "/products/3/photos/4" for 69.149.172.21 at Fri Dec 10 14:52:29 -0800 2010
Processing by PhotosController#update as HTML
Parameters: {"photo"=>{"title"=>"Front"}, "commit"=>"Update Photo", "product_id"=>"3", "authenticity_token"=>"uZ3dV3BCSm7GvP39U51KCClx2P8gIWktyki/3rnpOIM=", "utf8"=>"\342\234\223", "id"=>"4"}
[paperclip] Saving attachments.
Redirected to http://leatherarts.heroku.com/products/3
Completed 302 Found in 17ms
What am I missing?
I ignored the authenticity token in the controller for the update action... btw
Picnik takes a basic params to submit back to by post, my line looks like this:
<%= link_to "Edit or Crop", "http://www.picnik.com/service/?_import=img&img=#{#photo.data.url(:original)}&_export=#{url_for(product_photo_url(#product,#photo))}&_export_field=photos_attributes&_export_title=SaveIt&_apikey=617c5c06600b6c21ebf0bc91eafbbae5" %>
Photo Model
has_attached_file :data,
:storage => 's3',
:s3_credentials => "#{RAILS_ROOT}/config/s3_credentials.yml",
:bucket => 'leatherarts.com',
:s3_host_alias => 'leatherarts.com.s3.amazonaws.com',
:url => ':s3_alias_url',
:path => "images/products/:product_id/:style/:basename.:extension",
:styles => { :thumb => "60x60#", :small => "200x200>", :medium => "400x400>", :large => "1000x1000>" },
:default_style => :original,
:default_url => 'http://leatherarts.com.s3.amazonaws.com/images/records/m1.png',
:s3_headers => { 'Expires' => 2.months.from_now.httpdate }
validates_attachment_presence :data
validates_attachment_size :data, :less_than => 10.megabytes
validates_attachment_content_type :data, :content_type => ['image/jpeg','image/gif','image/png']
UPDATE:
I got past the first problem with a specified PUT in a new route:
match 'products/:product_id/photos/:id/picnik' => 'photos#picnik', :as => :picnik
but still can't quite get it to all fall together. It seems to work and save, but it never saves the updated image.
I added this action in my photo controller
def picnik
#product = Product.find(params[:product_id])
#photo = Photo.find(params[:id])
#photo.data(params[:data])
if #photo.save
flash[:notice] = "Successfully updated photo."
redirect_to product_path(#product)
else
render :action => 'edit'
end
end
And according to the log it seems to do what it should:
Started POST "/products/10/photos/25/picnik" for 208.88.21.59 at Sat Dec 11 08:09:32 -0800 2010
Processing by PhotosController#picnik as HTML
Parameters: {"data"=>#<File:/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/RackMultipart20101211-7501-1tdkwuq-0>, "product_id"=>"10", "id"=>"25"}
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "x60" -crop "60x60+15+0" +repage '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-42lphg-0' 2>/dev/null
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "1000x1000>" '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-1nskgrl-0' 2>/dev/null
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "400x400>" '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-fpe5rc-0' 2>/dev/null
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "200x200>" '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-v5e99x-0' 2>/dev/null
[paperclip] saving images/products/10/original/DSC_0212.JPG
[paperclip] saving images/products/10/etsy/DSC_0212.JPG
[paperclip] saving images/products/10/thumb/DSC_0212.JPG
[paperclip] saving images/products/10/medium/DSC_0212.JPG
[paperclip] saving images/products/10/small/DSC_0212.JPG
[paperclip] Saving attachments.
Redirected to http://leatherarts.heroku.com/products/10
Completed 302 Found in 1632ms
But it's always the same image as before, with no new adjustments from picnik? I thought maybe it was the S3 Caching, but I created a new size category and it created it with the old image just the same.

Resources