4

I am getting an error when trying to save a png to a model with a paperclip attachment.

My User model:

class User < ActieRecord::Base
  attr_accessible :icon
  has_attached_file :icon, :url => "/system/users/icon/:hash.:extension",
    :hash_secret => "superSecretHashSecret",
    :styles => { :medium => "300x300>", :thumb => "100x100>" }
end

Example of trying to set an icon:

u = User.last
u.icon = open(Rails.root + "spec/fixtures/files/example.png")
u.save

Example model error:

:icon => ["/var/folders/43/810gn/T/example20121104-36855-1v7t136.png is not recognized by the 'identify' command."]

There are a number of people who have posted similar questions to this one, especially this one but none of those solutions work for me.

My command_path is set correctly:

O:~ $ which identify
/usr/local/bin/identify

In development.rb

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

This still might be the problem though. When trying to use `identify directly I get the following error:

O:~ $ identify workspace/app/spec/fixtures/files/example.png 
dyld: Library not loaded: /usr/lib/libltdl.7.dylib
  Referenced from: /usr/local/bin/identify
  Reason: image not found
Trace/BPT trap: 5

Any suggestions as to what is going on here?

I have tried reinstalling ImageMagick

brew unlink imagemagick
brew install imagemagick

Others have recommended adding Rmagick. It is definitely not a requirement for using Paperclip and it also did not help.

Another solution that has been suggested is removing the :style property. That isn't a solution though. I need to do the processing on the images.

I have Paperclip working on another model in my project that handles documents that are not images/don't do any processing. So I know that it is probably related to that.

Any other suggestions on how to address this problem?

Community
  • 1
  • 1
Andrew Hubbs
  • 9,338
  • 9
  • 48
  • 71

4 Answers4

9

This is an ImageMagick installation problem.

First try

brew update
brew upgrade imagemagick

If that doesnt work, use magick-installer script to solve this: https://github.com/maddox/magick-installer

curl https://raw.github.com/maddox/magick-installer/master/magick-installer.sh | sh

Alternatively, use a fork of magick-installer with newer versions of dependent libraries:

curl https://raw.github.com/GTSouza/magick-installer/master/magick-installer.sh | sh
glebm
  • 20,282
  • 8
  • 51
  • 67
  • Thanks glebm. I got it working by wrangling directly with homebrew for a while (seems likely this would have saved me the trouble though). – Andrew Hubbs Nov 05 '12 at 00:08
5

The solution ended up being to install libtool. This was the best suggestion here as well. My issue proved more complicated because of homebrew not being up to date and in a state where it could not be updated without forcing a checkout of master.

For people that face this issue in the future, I recommend manually checking that the identify command actually works even if it is in your path.

identify /path/to/some/image

If it fails it will show something like:

O:~ $ identify workspace/app/spec/fixtures/files/example.png 
dyld: Library not loaded: /usr/lib/libltdl.7.dylib
  Referenced from: /usr/local/bin/identify
  Reason: image not found
Trace/BPT trap: 5

In this case try installing libtool.

brew install libtool

If this fails, run brew update. If it continues to fail ensure that you have the latest Xcode installed and try updating again.

You will know this worked if you can successfully use identity. It will look something like this:

O:~ $ identify ~/workspace/app/spec/fixtures/files/example.png 
~/workspace/app/spec/fixtures/files/example.png PNG 200x201 200x201+0+0 8-bit DirectClass 66.1KB 0.000u 0:00.000

The answer from glebm may very well have worked too. I have not taken a look at that installer.

Community
  • 1
  • 1
Andrew Hubbs
  • 9,338
  • 9
  • 48
  • 71
0

This may caused by using old versions of Paperclip with newer and incompatible versions of the Cocaine gem. You can update paperclip gem version by using bundle update paperclip. It will update paperclip and cocaine versions as per compatibility.

https://github.com/thoughtbot/paperclip/issues/1038

RAJ
  • 9,697
  • 1
  • 33
  • 63
0

I just ran into this same issue after upgrading to Mavericks on my Mac.

Here are the steps that fixed the problem:

brew update
brew install libtool
brew link libtool
brew upgrade imagemagick
kirley
  • 330
  • 2
  • 10