I'm using ImageMagick along with paperclip to upload images in a RoR application. The problem is that the command 'identify' is causing trouble. My app throws the following error "Image Paperclip::Errors::NotIdentifiedByImageMagickError". Looking deep into the logger, I found:
Command :: identify -format '%wx%h,%[exif:orientation]' "C:/Users/<...>" 2>NUL
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: identify -format '%wx%h,%[exif:orientation]' "C:/Users/<...>" 2>NUL
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
And then I tried to wirte the problematic commad into my cmd and it throws
identify: unknown image property "%[exif:orientation]" # warning/property.c/InterpretImageProperties/3904
I'm using Windows and I have installed ImageMagick 7.0.7 with legacy options.
The problem isn't that I don't know how to get the orientation. The problem is that when I upload an image and try to create the 'profiles'
has_attached_file :image,
styles: { thumb: ["64x64#", :jpg],
original: ['500x500>', :jpg] },
convert_options: { thumb: "-quality 75 -strip",
original: "-quality 85 -strip" }
Paperclip makes an automatic call to that command to get the orientation and my console does not seem to recognize that command.
Related
I've seen similar post with this error but none of them fixed my problem. I'm using ImageMagick (6.9.0.8)and Paperclip for uploading images to my Rails 4 app. It is working on my development machine, a Mac, but not on my DigitalOcean account (Ubuntu 14.04, Nginx, Unicorn). When Paperclip tries saving different sizes of the images, ImageMagick give the error:
Paperclip::Errors::NotIdentifiedByImageMagickError
I'm using the Paperclip 4.2.1 and Cocaine .0.5.5 gems. In my Rails model I have:
has_attached_file :photo_image, :styles => { :medium => "330x250#", :small => "150x120#", :thumb => "120x100#" },
:url => "/system/dadverts/:attachment/:id/:style/:filename",
:path => ":rails_root/public/system/dadverts/:attachment/:id/:style/:filename",
:default_url => "300250ad.png"
validates_attachment_content_type :photo_image, :content_type => /\Aimage/
In my production environment settings I have:
Processing by AdvertisementsController#create as HTML
I, INFO -- : Parameters: {"utf8"=>"✓", "authenticity_token"=>"8hHWBxpydUyA1MEucXtnSvvRvHc38LcM1hbb8Is/cd4=", "advertisement"=>{"customer_name"=>"Kayak Venice", "ad_network_name"=>"Recon Outpost", "sitead_location_id"=>"1", "publish_date(1i)"=>"2015", "publish_date(2i)"=>"3", "publish_date(3i)"=>"14", "expiration_date(1i)"=>"2020", "expiration_date(2i)"=>"3", "expiration_date(3i)"=>"14", "keywords_alt_text"=>"", "sort_order"=>"1", "local_ad"=>"0", "zipcode"=>"00000", "photo_image"=>#<ActionDispatch::Http::UploadedFile:0x00000005c93038 #tempfile=#<Tempfile:/tmp/RackMultipart20150314-2186-1jc6u31>, #original_filename="KayakLogoConcept3.png", #content_type="image/png", #headers="Content-Disposition: form-data; name=\"advertisement[photo_image]\"; filename=\"KayakLogoConcept3.png\"\r\nContent-Type: image/png\r\n">, "render_options"=>"1", "click_thru_url"=>"", "external_media_embed"=>""}, "advertisment"=>{"publish"=>"0"}, "commit"=>"Create Advertisement"}
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH file -b --mime '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-pxyhur.png'
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH identify -format '%wx%h,%[exif:orientation]' '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-o1r33b.png[0]' 2>/dev/null
I, INFO -- : [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH identify -format '%wx%h,%[exif:orientation]' '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-o1r33b.png[0]' 2>/dev/null
I, INFO -- : [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH identify -format '%wx%h,%[exif:orientation]' '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-o1r33b.png[0]' 2>/dev/null
I, INFO -- : [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH file -b --mime '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-91e4eo.png'
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH identify -format '%wx%h,%[exif:orientation]' '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-fwjtt8.png[0]' 2>/dev/null
I, INFO -- : [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH identify -format '%wx%h,%[exif:orientation]' '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-fwjtt8.png[0]' 2>/dev/null
I, INFO -- : [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH identify -format '%wx%h,%[exif:orientation]' '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-fwjtt8.png[0]' 2>/dev/null
I, INFO -- : [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH file -b --mime '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-k19vf3.png'
I, INFO -- : Rendered advertisements/_form.html.erb (65.2ms)
This error class has description:
# Will be thrown when ImageMagic cannot determine the uploaded file's
# metadata, usually this would mean the file is not an image.
This is mean that you are trying to process not image file. Seems like it can be related to incorrect extension of temporary file. Look at this file extension:
af961aaf697aaa71682a6e9716d6034520150314-2186-o1r33b.png[0]
As you can see it has [0] at the end. So, try to investigate why this extension is appear. Seems like you are using custom processor base on Cocaine. I think problem can be related to it.
Anything new for this issue?
I got the same problem and open a new issue on github:
https://github.com/thoughtbot/cocaine/issues/84
I have a model:
class PropertyImage < ActiveRecord::Base
has_attached_file :picture,
storage: :s3,
s3_credentials: CONFIG['s3'],
s3_protocol: (Rails.env.development? ? "http": "https"),
styles: {
thumb: '100x100>',
large: '633x460>',
medium: '301x240>'
}
end
I'm using Rails (4.0.1), cocaine (0.5.4) and paperclip (3.5.4).
I want to migrate old images (with no thumb, large and medium) and resize each, so I created a rake script:
namespace :migrate_images do
desc "Resize Images in PropertyImage"
task start_migration: :environment do
PropertyImage.not_migrated.find_each do |pi|
ImageConverter.perform(pi)
end
end
end
And ImageConverter class:
class ImageConverter
def self.perform(pi)
begin
pi.picture.reprocess!
pi.update_attributes!({migrated: true})
puts "PropertyImage [#{pi.id}] has been migrated."
rescue Exception => e
puts "PropertyImage [#{pi.id}] has an error. #{e}"
end
end
end
Now when I run the script I keep getting the following error:
⇒ bundle exec rake migrate_images:start_migration
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
PropertyImage [11] has an error. Validation failed: Picture Paperclip::Errors::NotIdentifiedByImageMagickError, Picture Paperclip::Errors::NotIdentifiedByImageMagickError, Picture Paperclip::Errors::NotIdentifiedByImageMagickError
PropertyImage [12] has an error. Validation failed: Picture Paperclip::Errors::NotIdentifiedByImageMagickError, Picture Paperclip::Errors::NotIdentifiedByImageMagickError, Picture Paperclip::Errors::NotIdentifiedByImageMagickError
Please note that I read similar articles and added the following to the end of application.rb:
Paperclip.options[:command_path] = "/usr/local/bin/identify"
And I made sure I have imagemagick installed:
⇒ brew install imagemagick
Warning: You have an outdated version of /usr/bin/install_name_tool installed.
This will cause binary package installations to fail.
This can happen if you install osx-gcc-installer or RailsInstaller.
To restore it, you must reinstall OS X or restore the binary from
the OS packages.
Warning: imagemagick-6.8.9-7 already installed
Any help would be highly appreciated.
Please note if I try to reproduce the problem using rails console:
>> p = Property.find(93746)
>> p.property_images.each do |pi|
?> pi.picture.reprocess!
>> end
PropertyImage Load (1.4ms) SELECT "property_images".* FROM "property_images" WHERE "property_images"."invalid_image" = 'f' AND "property_images"."property_id" = $1 ORDER BY "property_images"."apartment_main" DESC [["property_id", 93746]]
[paperclip] copying /property_images/pictures/000/325/476/original/722952f7-4cd4-47bb-bdcf-c7411c9d6021.jpg to local file /var/folders/g8/3v37gc0x16b313mvf7464qtc0000gn/T/dfe10026af3ac1b8cc5c94f00437092020141027-6352-12gmkmc.jpg
[AWS S3 200 1.212736 0 retries] get_object(:bucket_name=>"my_bucket_development",:key=>"property_images/pictures/000/325/476/original/722952f7-4cd4-47bb-bdcf-c7411c9d6021.jpg")
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/g8/3v37gc0x16b313mvf7464qtc0000gn/T/dfe10026af3ac1b8cc5c94f00437092020141027-6352-12gmkmc.jpg[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/g8/3v37gc0x16b313mvf7464qtc0000gn/T/dfe10026af3ac1b8cc5c94f00437092020141027-6352-12gmkmc.jpg[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/g8/3v37gc0x16b313mvf7464qtc0000gn/T/dfe10026af3ac1b8cc5c94f00437092020141027-6352-12gmkmc.jpg[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
[paperclip] saving /property_images/pictures/000/325/476/original/722952f7-4cd4-47bb-bdcf-c7411c9d6021.jpg
[AWS S3 200 0.293473 0 retries] put_object(:acl=>:public_read,:bucket_name=>"my_bucket_development",:content_length=>0,:content_type=>"image/jpeg",:data=>Paperclip::AttachmentAdapter: 722952f7-4cd4-47bb-bdcf-c7411c9d6021.jpg,:key=>"property_images/pictures/000/325/476/original/722952f7-4cd4-47bb-bdcf-c7411c9d6021.jpg")
(0.2ms) BEGIN
(0.2ms) ROLLBACK
Make sure that the format you are trying to upload is supported by Imagemagick on the server you are using.
To make sure of this, use this command:
convert -list format
If the format you are trying to upload with Paperclip is not in the list, you need to install the libraries needed and then reinstall/recompile Imagemagick.
Here is given an example of how to do that on a Unix machine. To install the jpg library, it is used the command:
yum install libjpeg libjpeg-devel
How to install the library and reinstall/recompile Imagemagick depends on which OS you use and on which image format you need.
I have a Picture model, which has attached file picture, using Paperclip.
class Picture < ActiveRecord::Base
[...]
has_attached_file :photography, styles: { thumb: '115x', gallery: '560x560' }
[...]
end
File corresponding to thumb style is perfect but file corresponding to gallery style is always 560px width. I want to obtain a file with every sides of 560px maximum.
Eg:
Original size 1000x800px => gallery size 560x468
Original size 800x1000px => gallery size 700x560
Paperclip debug output:
Started POST "/admin/pictures/create" for 127.0.0.1 at 2013-01-29 13:21:26 +0100
Processing by Admin::PicturesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"3mDW4HeWq3SV/KJ8ez09c+/Y1dNcCkqN+8uUUx5SnGk=", "picture"=>{"realization_id"=>"3", "photography"=>#<ActionDispatch::Http::UploadedFile:0x007fe984776c10 #original_filename="IFFTS-37-2.jpeg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"picture[photography]\"; filename=\"IFFTS-37-2.jpeg\"\r\nContent-Type: image/jpeg\r\n", #tempfile=#<File:/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/RackMultipart20130129-12408-a9zr3v>>, "name"=>"test", "active"=>"1"}, "_save"=>"Save"}
Command :: identify -format %wx%h '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]'
Command :: identify -format %m '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]'
Command :: identify -format %m '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]'
Command :: convert '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]' -auto-orient -resize "115" '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja20130129-12408-1boh1t1'
Command :: file -b --mime '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja20130129-12408-1boh1t1'
Command :: identify -format %wx%h '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]'
Command :: identify -format %m '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]'
Command :: identify -format %m '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]'
Command :: convert '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]' -auto-orient -resize "560x560" '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja20130129-12408-fqtxxs'
Command :: file -b --mime '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja20130129-12408-fqtxxs'
If I run the same command in terminal, everything works fine:
convert picture.jpeg -auto-orient -resize 560x560 picture.jpeg
(Same issue on Heroku)
Any ideas ?
Try Following
has_attached_file :photography, styles: { thumb: '115x', gallery: '560x560>' }
I suggest you to stop using paperclip since its heavy and use carrierwave. Its quite light. I was using paperclip initially and then switched to carrierwave. Pretty simple to deploy.
I'm running a rails 3.0.12 application with Paperclip 2.6 under Ubuntu + Nginx + Unicorn setup. In production, my image attachments seemed to upload fine, but upon checking the image path, I couldn't find the files, so I started messing around.
Ultimately, I found that if I ran the built-in rails dev server (rails s), the attachments would upload just fine to the correct path. But under unicorn, while the attachments do get uploaded, a) they get saved to /tmp/randompath on the server, and all the resized images for each of the styles also get saved with a bunch of random characters in the filename, including the upload date and time.
Not sure what is going on here. Here is the rails log when run under the rails dev server (in the production environment):
Command :: identify -format %wx%h '/tmp/stream20120626-4215-axmd16.png[0]'
Command :: convert '/tmp/stream20120626-4215-axmd16.png[0]' -resize "x100" -crop "100x100+185+0" +repage '/tmp/stream20120626-4215-axmd1620120626-4215-1droo3w'
Command :: identify -format %wx%h '/tmp/stream20120626-4215-axmd16.png[0]'
Command :: convert '/tmp/stream20120626-4215-axmd16.png[0]' -resize "280x" -crop "280x55+0+2" +repage '/tmp/stream20120626-4215-axmd1620120626-4215-fzxeg1'
...
...
UPDATE `organizations` SET `logo_file_name` = 'logo.png', `logo_file_size` = 5682, `logo_updated_at` = '2012-06-26 19:48:47', `updated_at` = '2012-06-26 19:48:48' WHERE `organizations`.`id` = 1
[paperclip] Saving attachments.
[paperclip] saving /home/deploy/apps/xxx_staging/releases/20120626193037/public/system/organization/1/original/logo.png
[paperclip] saving /home/deploy/apps/xxx_staging/releases/20120626193037/public/system/organization/1/thumb/logo.png
And under unicorn, the log shows:
Command :: identify -format %wx%h '/tmp/1docway_logo20120626-11230-1wodane.jpg[0]'
Command :: convert '/tmp/1docway_logo20120626-11230-1wodane.jpg[0]' -resize "x100" -crop "100x100+135+0" +repage '/tmp/1docway_logo20120626-11230-1wodane20120626-11230-1y0j5hm'
Command :: identify -format %wx%h '/tmp/1docway_logo20120626-11230-1wodane.jpg[0]'
Command :: convert '/tmp/1docway_logo20120626-11230-1wodane.jpg[0]' -resize "280x" -crop "280x55+0+10" +repage '/tmp/1docway_logo20120626-11230-1wodane20120626-11230-1bwx4go'
[paperclip] Saving attachments.
[paperclip] deleting /home/deploy/apps/xxx_staging/releases/20120620214744/public/organization/1/original/1docway_logo.png
[paperclip] deleting /home/deploy/apps/xxxx_staging/releases/20120620214744/public/organization/1/thumb/1docway_logo.png
As you can see, the second set of logs has no UPDATE command being run, or files being saved to the /home/deploy/apps/xxx_staging/releases/xxx/public/system/ folder
my app integrates with FB. When the user has no image, FB returns:
https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v1/yp/r/yDnr5YfbJCH.gif
While that looks like a normal gif, it breaks paperclip:
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "x50" -crop "50x50+14+0" +repage '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-1r9c5af-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "300x300>" '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-1cjw8np-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "100x100>" '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-1n3nk3x-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "x25" -crop "25x25+7+0" +repage '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-rhm4uk-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
Even with the error, paperclip still saves the image to the model.
Questions:
Why is it breaking?
How can I tell paperclip that if there is a processing error, abort the image, not the entire process as I'm also saving names etc, but at least stop the image from saving a dead file that ends up 404ing.
Thanks
It looks like it is actually a corrupt image. Downloading it and running identify -format %wx%h yDnr5YfbJCH.gif throws the error:
identify: corrupt image `yDnr5YfbJCH.gif' # error/gif.c/PingGIFImage/958.
200x126
So you can blame Facebook for that one.
Rob on Rails has a good example on how to validate that an upload is a valid image. That should make things work nicely for your end users.