Thursday, May 30, 2013

imageMagick on mac os

Recently, I'm working on a mac os, creating a website using Rails.
I want the user to be able to upload a picture as an avatar. I found excellent
information on Internet. The most popular library is probably Paperclip (https://github.com/thoughtbot/paperclip).
Paperclip is intended as an easy file attachment library for Active Record.


After installing Paperclip and  ImageMagick (with brew), I added the code in my model :
attr_accessible :avatar, :name
has_attached_file :avatar, :styles => { :medium=>"300x300>", :thumb => "100x100>"},
  :url  => "/assets/restaurants/:id/:style/:basename.:extension",
  :path => ":rails_root/public/assets/restaurants/:id/:style/:basename.:extension"

It's exactly like in the wiki page of Paperclip (nothing fancy).

Problem :
But when I tried to upload an image, I had this error :
 ... is not recognized by the 'identify' command.

On Internet, many people said to do:
which identify
#/usr/local/bin/identify
And then add in config/environment.rb:
Paperclip.options[:command_path] = "/usr/local/bin"

But this didn't work for me.
If I just tried the command "identify", I could see this error :
dyld: Library not loaded: /usr/local/lib/libtiff.3.dylib
  Referenced from: /usr/local/bin/identify
  Reason: image not found
Trace/BPT trap: 5

So I was thinking there is a problem with the file "libtiff.3.dylib".

Solution :
I copied the file libtigg.3.dylib :
from : /opt/local/lib/libtiff.3.dylib
to : /usr/local/lib/libtiff.3.dylib

I restarted my rails server, and now it's working !
It's probably not the best solution, but at least it's working so far.
I think ImageMagick is looking for the file libtiff.3.dylib in a wrong folder.
Maybe if I could modify ImageMagick config file and change to the good folder, this
would be a better solution.

And that's it !