PaperClip Error NotIdentifiedByImageMagickError when scaling images
Asked Answered
C

11

23

I have been banging my head against this for several days. Recently, my image uploader has stopped working properly. I have investigated several possibilities, but have none of the suggested solutions have worked in my case.

The error message is:

#<Paperclip::Errors::NotIdentifiedByImageMagickError:Paperclip::Errors::NotIdentifiedByImageMagickError> 

Here are the details:

  • Mac OS X 10.8.3
  • ImageMagick 6.8.4-4 2013-03-29
  • libtool => /usr/bin/libtool
  • Rails 3.2.13
  • Ruby 1.9.3p194

development.rb contains appropriate path (and I have verified that it is correct using which identify)

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

Gemfile.lock (relevant portion)

paperclip (3.4.1)
  activemodel (>= 3.0.0)
  activerecord (>= 3.0.0)
  activesupport (>= 3.0.0)
  cocaine (~> 0.5.0)

MODEL (I am updating a classroom object, but the picture resides in the location model. (Classroom has_one :location, :as => :locatable)

Model location.rb

class Location < ActiveRecord::Base
  ## Paperclip method for uploading location images

  has_attached_file :picture, :styles => {:show => "1200x500#", :medium => "300x300#", :thumb => "100x100>"}, :convert_options => {:show => "-gravity center"}  
  has_attached_file :building_sign, :styles => { :show => ["1200x500#", :jpg], :medium => ["300x300#", :jpg], :thumb => ["100x100#", :jpg] }, :convert_options => {:show => "-gravity center"}
  belongs_to :locatable, :polymorphic => true
  belongs_to :location_type  
  validates :name,  :presence => true

  validates :latitude, :presence => true,
                       :length => {:within => 9..18},
                       :numericality => true
  validates :longitude, :presence => true,
                        :length => {:within => 9..18},
                        :numericality => true
end

Controller classrooms_controller.rb

def update
  @classroom = Classroom.find_by_facility_code_heprod(params[:id].upcase)

  respond_to do |format|
    if @classroom.update_attributes(params[:classroom])
      format.html { redirect_to(@classroom, :notice => 'Classroom was successfully updated.') }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @classroom.errors, :status => :unprocessable_entity }
    end
  end
end

What I've tried.

  • I've made sure that the image name is simple (USB2230.jpg), no colons.
  • I've updated the version of ImageMagick to the most recent.
  • I've also re-downloaded and reinstalled the CommandLine Tools for 10.8.3 (someone suggested that the issue might be related to an outdated libtool).
  • I've rebooted the computer.
  • I've tried variations on gem versions including

    # variation 1
    gem 'paperclip', '~> 2.8.0'
    gem "cocaine", "=0.3.2"
    
    # variation 2
    gem "paperclip", "~> 3.4.0"
    gem "cocaine", "= 0.4"
    
    # variation 3 (which is what is reflected in the included Gemfile.lock info above).
    gem "paperclip", "~> 3.4.0"
    

If I remove the scaling,

:styles => {:show => "1200x500#", :medium => "300x300#", :thumb => "100x100>"},
:convert_options => {:show => "-gravity center"}

the upload works, but I kind of need the scaling ;-)

Can anyone see something I am missing?

Covenant answered 1/4, 2013 at 13:57 Comment(0)
B
1

I just solved this issue. brew makes a directory call Cellar, /usr/local/Cellar Verify if you don`t have two ImageMagick, i had one named ImageMagick-Ruby182, so, if you have it run brew uninstall ImageMagick-Ruby182, and also the normal imagemagick, and reinstall image magic.

Backset answered 3/3, 2016 at 7:28 Comment(0)
H
22

We just ran into this issue, and it turned out to be an issue where ghostscript wasn't installed. I took the advise of Scott Cornwell and removed the silencing of errors, and then determined that convert was failing because ghostscript wasn't available.

   brew install ghostscript 

Fixed the issue for us.

Hamford answered 25/6, 2013 at 18:9 Comment(2)
This was exactly the cause of my problem - I was using Paperclip to upload and thumbnail PDFs. Not having Ghostscript installed led to sadness.Vallejo
Perfect, this solved my issue! I was trying to simply upload a pdf - not doing thumbnails or any manipulation on it. The error message is a bit misleading unless paperclip tries to create a thumbnail for you from the pdf without an explicit request.Mendelian
W
10

I had the same issue, although my server is on Linux. Can't tell you exactly how to do it because I don't have a Mac to test, but hopefully this points you in the right direction.

This worked for me with ImageMagick 6.8.5-5, Paperclip 3.4.2, latest version of cocaine, Rails 3.2.13:

I went into geometry_detector_factory.rb in the Paperclip gem and commented out the 2 lines around the identify call: (this step is not necessary, just explaining what I did to determine the problem)

#silence_stream(STDERR) do 
    Paperclip.run("identify", "-format '%wx%h,%[exif:orientation]' :file", :file => "#{path}[0]")
#end

along with the corresponding "end" statement. This allowed me to see the errors on the command line when running the "identify" command.

Basically the error said: "no decode delegate for this image format"

You can probably look up that error and get it figured out, but basically what I did was go to usr/local/bin and run: (also not necessary, unless you want to see what you have installed)

convert -list configure

and look for the DELEGATES line. I had another Linux server where ImageMagick was working and after comparing the two I realized the new one had only 2 delegates installed. I was able to run:

yum install ImageMagick-devel

and then recompile ImageMagick with make, make install and it worked.

You can also find the delegates manually on the ImageMagick site and install them one by one but that library pretty much covered it for me.

Debugging ImageMagick? Ain't nobody got time for that!

Whinny answered 28/5, 2013 at 23:53 Comment(2)
Thank you! That worked on my client machine. (I ended up using mac ports, which I was loathe to do, but I was spending too much time debugging this.) The instructions I followed were here (imagemagick.org/script/binary-releases.php#macosx). I also had to change my development environment to point to Paperclip.options[:command_path] = "/opt/local/bin/"Covenant
What about Ubuntu? :/ Same problem here, still haven't found a solutionRegardant
C
6

Had the problem on my window dev environment, using paperclip 3.5.2, cocaine 0.5.3, and ImageMagic 6.8.8.

Solution was to add:

Paperclip.options[:command_path] = 'C:\Program Files\ImageMagick-6.8.8-Q16'

to config/environment/development.rb

Cellulous answered 17/1, 2014 at 11:3 Comment(0)
D
3

I had similar issue, but older PaperClip (3.0.2).

In my case I fixed it with:

gem 'cocaine', '0.3.2'
Dubitation answered 27/4, 2013 at 21:29 Comment(0)
I
1

Reinstalling libtool brew install libtool worked for me.

Idler answered 18/7, 2013 at 20:39 Comment(0)
B
1

I just solved this issue. brew makes a directory call Cellar, /usr/local/Cellar Verify if you don`t have two ImageMagick, i had one named ImageMagick-Ruby182, so, if you have it run brew uninstall ImageMagick-Ruby182, and also the normal imagemagick, and reinstall image magic.

Backset answered 3/3, 2016 at 7:28 Comment(0)
C
0

Please update the version of paperclip gem and cocaine gem. Set PaperClip version: 3.4.1 Set Cocaine version: 0.5.

I faced the same problem and my issue was already there in paperclip gem github issues

Curvy answered 4/4, 2013 at 6:45 Comment(1)
The version is already at 3.4.1 and cocaine is at 0.5.0 (as indicated in the Gemfile.lock listed above).Covenant
B
0

You already mentioned that you tried upgrading ImageMagick, but I had the same issue and upgrading to ImageMagick 6.8.0-10 2013-03-03 fixed it for me.

Brundisium answered 14/5, 2013 at 1:39 Comment(0)
A
0

Had same issue with image_magic that was breaking our paperclip functionality in production, but not in development (weird, I know). Yet even after removing imagemagick from our gemfile and Gemfile.lock locally (running bundle install and all that stuff) and then deploying back to production on heroku, the error persisted in production! (weird, I know).

What ended up doing the trick was running:

$ heroku repo:purge_cache -a myAppName

(Taken from: https://github.com/heroku/heroku-repo#purge_cache)

When you deploy your app, Heroku caches some things like your assets and installed gems in order to speed up deployment. Although this is a great feature, it can have side-effects sometimes, and in this case, it seems that something about the imagemagick gem got "stuck" in production's cache, which is why purging solved the issue for us (since after purging, your app will rebuild itself from scratch on your next deployment)

Amalburga answered 26/11, 2014 at 17:47 Comment(0)
D
0

I have the same issue, and I solved it, when i configure the dynamic linker run-time bindings to create the necessary links and cache to the most recent shared libraries using the ldconfig command.

So you need to use the following command:

sudo ldconfig /usr/local/lib

Actually, I advice to re-install imagemagick using steps at how-to-install-image-magick-and-setup-paperclip.

Deferred answered 16/12, 2014 at 11:33 Comment(0)
R
0

Just for the record:

brew uninstall libtool
brew install libtool
brew uninstall jpeg
brew install jpeg
brew link --overwrite jpeg
brew unlink freetype && brew link freetype
Robinet answered 21/10, 2015 at 0:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.