paperclip error - ruby-on-rails

i am trying paperclip for the first time and followed this tutorial
all is well until i use styles. this is the code
has_attached_file :photo, :url => "/uploads/products/:id/:style/:basename.:extension",
:path => ":rails_root/public/uploads/products/:id/:style/:basename.:extension",
:styles => { :thumb=> "100x100#" }
the error i see on the console is
[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: C:/DOCUME~1/LOCALS~1/Temp/stream,2956,1.jpg is not recognized by the 'identify' command.>
what does this mean? I have no idea what it means. Should i install this ImageMagick?
I tried installing it as a plugin as per this page. This also returns an error that "plugin not found".
what am i missing here?
update: I am on windows xp. webrick server. I have rmagick gem

Run identify on your command prompt. If it identifies itself as ImageMagick, you have it installed. Next, get a jpg that you know opens in a viewer and try identify <image>.jpg. If it shows the image properties, you can be sure you have ImageMagick working properly. If not, depending on your OS, install IM again.
Sometimes, you might have to remove the preinstalled libjpeg and libpng libraries that come installed with your OS, for IM to install properly. Since you are on windows, you need not worry about this. Just follow the installation for windows from here: http://www.imagemagick.org/script/install-source.php and be sure to set the paths right.

in the source of paperclip.rb ,
if you change the line
option.split("'").map{|m| "'#{m}'" }.join("\'")
to the following:
option.split("'").map{|m| "\"#{m}\"" }.join("\'")
it works
Here is the complete changed method:
def quote_command_options(*options)
options.map do |option|
option.split("'").map{|m| "\"#{m}\"" }.join("\\'")
end
end

it means "identify" failed to tell what kind of file you uploaded, that might be caused by a bad file upload but also by a missing ImageMagick. I dont know how that is usually handled on windows.

You need install the ImageMagick
Ubuntu:
sudo apt-get install imagemagick

If you just installed imagemagick and you're on windows, it may help to do a "full reboot". I assume something wasn't stopping properly, and wasn't picking up the new path.
(probably just closing everything will work, but I just went for a full reboot to be sure)

Related

Can not upload image to Spree app

I try to upload a product image to my Spree app, but i get this error
5errors prohibited this record from being saved:
Attachment Paperclip returned errors for file 'index.jpg' - check ImageMagick installation or image source file.
Attachment Paperclip::Errors::NotIdentifiedByImageMagickError
Attachment Paperclip::Errors::NotIdentifiedByImageMagickError
Attachment Paperclip::Errors::NotIdentifiedByImageMagickError
Attachment Paperclip::Errors::NotIdentifiedByImageMagickError
Should i install a gem, relocate my src image? Whats the problem here
You should to install ImageMagick. Follow these steps for install on Windows:
Download ImageMagick (you need to choose static version for your 32/64 bit OS)
Checked Add application directory to your system path and install
Reopen your command prompt to reload your PATH variables
Run convert -v to check the install worked
Okay so the problem is pretty complicated and after trying to solve it for about 3 hours i finally got it.
First, you have to remove the convert.exe from your System32 files.
We do this, because the Spree app relies on legacy code and when it
tries to upload the image the default convert.exe starts, we don't
want that.
Second you download and install the dynamic installation from the imagemagick site and you have to be sure to check the legacy support so the convert command gets supported.
I dont know if you have to, but i installed the paperclip gem. You may have to do that for it to work.
The whole reason this bug happens, is because Windows. So if you are new to this party, dual boot your station or swap to Ubuntu/Mac whatever. Seriously though, when the app tries to upload it uses the convert command, but convert is already a default Windows command so you can't upload the picture properly. So we disable the command and then we replace it with our imagemagick installation. That's it.Also good luck trying to delete the convert.exe from system32, its a weird process, but you can solve it with some google-fu.
Thanks to Michael for pointing me to right way.

Paperclip can't find imagemagick

Okay, I have imagemagick installed on my local machine via homebrew, and Gemfile.lock shows paperclip locked at version paperclip (3.0.4).
Per the setup instructions, I set the following command in development.rb
Paperclip.options[:command_path] = "/usr/local/bin/"
Which lines up with what the terminal says
$ which identify
# => /usr/local/bin/identify
However, when I try to upload an image, the following error spits out on my form
/var/folders/dm/lnshrsls2zz6l4r_tkbk7j2w0000gn/T/avatar20120522-44111-gfis2q.jpg is not recognized by the 'identify' command.
Which every SO question I can find on the matter suggests the problem is Paperclip can't find identify in it's command path.
I used the Paperclip generator to add the avatar to my database, and my model has:
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
Furthermore, if I load up rails c and look at Paperclip.options, I can see the command path has been properly set in the hash.
Not quite sure what to do at this point. Any help would be appreciated.
I'm glad that running the command got you started on the right path.
The problem was that your ImageMagick was compiled for the wrong architecture:
dyld: Library not loaded: /usr/local/lib/libtiff.3.dylib Referenced from: /usr/local/bin/identify Reason: image not found Trace/BPT trap
Uninstalling imagemagick, updating homebrew and reinstalling it was the right thing to do.
Just in case, I made it work with this trick:
ln -s /usr/local/Cellar/libtiff/3.9.5/lib/libtiff.3.dylib /usr/local/lib/libtiff.3.dylib
And is working like charm :)
Not quite sure what the exact problem was, however I uninstalled Image Magick, updated Homebrew and reinstalled imagemagick and now everything is working.

Paperclip fails when styles are applied - ImageMagick installed - Win 7 - Rails -

I've got paperclip working so that I can upload and edit a photo but when I try to apply styles to it it falls over.
Invalid argument - convert
ImageMagick is installed but I'm not sure if it's installed properly - when I tested the install with the convert logo: logo.gif it creates the logo but I have to open it from explorer - it won't let me from the command line - as per instructions. (I'm not sure if this is an issue?)
# Paperclip
has_attached_file :photo, :styles => { :thumb => "150x115>" }
If I rename the the ImageMagick folder I get a different error undefined method "exitstatus" which suggests to me that paperclip is talking to it but there's another issue?
Got it!!
Not sure what was going on but a system reboot sorted it. I suspect it had something to do with ImageMagick setting it's root path. I had re-installed it several times trying to get it to work.
I don't have Windows 7, but can definitely confirm that it has to do with the installation of ImageMagick, and nothing to do with how you've used the paperclip gem.
Once ImageMagick is installed correctly, you should be able to run the convert command from Cygwin.
Did you run the installer from here?

Remove unncessary error raised by paperclip - filename is not recognized by the 'identify' command

I've been searching on how to solve this issue but could not find any real and working solution.
User model:
validates_attachment_content_type :avatar, :content_type => ['image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png', 'image/gif']
Unnecessary error shows up when invalid file type is uploaded:
Avatar /tmp/sample,23283,0.txt is not recognized by the 'identify' command.
Server details:
Ubuntu and Debian
which identify
results to
/usr/bin/identify
Specifying command path does not solve the issue:
Paperclip.options[:command_path] = "/usr/bin"
Any ideas?
I looked at geometry.rb file and there seems to be something wrong with it.
def self.from_file file
file = file.path if file.respond_to? "path"
geometry = begin
Paperclip.run("identify", %Q[-format "%wx%h" "#{file}"[0]])
rescue PaperclipCommandLineError
""
end
parse(geometry) ||
raise(NotIdentifiedByImageMagickError.new("#{file} is not recognized by the 'identify' command."))
end
Let me know if anyone has solved the same issue and how. Many thanks.
I've had the same problem - the Paperclip code is not at fault.
In my setup I'm on MacOSX with a binary download of ImageMagick in /usr/local/ImageMagick-6.6.1/bin and I'm running Rails under Apache/Passenger. I've got Paperclip installed as a plugin.
There are 3 steps needed to get this working:
1: Make sure you have ImageMagick working at the UNIX command line level. This involves adding it to your path and exporting these environment variables (pointing to your ImageMagick installation, of course)
MAGICK_HOME=/usr/local/ImageMagick-6.6.1
DYLD_LIBRARY_PATH=/usr/local/ImageMagick-6.6.1/lib
Check that identify works with your images at the command line level.
2: Tell Paperclip where to find the ImageMagick executables
In config/environment.rb add this at the bottom of the file
Paperclip.options[:command_path] = "/usr/local/ImageMagick-6.6.1/bin"
At this point, after restarting Passenger, you would see that 'identify' is run from within Paperclip but is not able to identify the file... the final step is...
3: Identify needs those two exported environment variables - and Apache/Passenger (or other web servers probably) does not pass those through by default!
In your passenger vhost file add these lines:
SetEnv MAGICK_HOME /usr/local/ImageMagick-6.6.1
SetEnv DYLD_LIBRARY_PATH /usr/local/ImageMagick-6.6.1/lib
Restart apache/passenger and it should work
Good Luck!
You should have imagemagick installed which provides the identify command, and its path has to be in the $PATH variable of the user rails is running as.
It is used by paperclip for the scale and image manipulation options, but it is not documented as dependency because you "can" use paperclip without it if you accept the images as they come.
I hope it helps.
http://github.com/thoughtbot/paperclip/issues/issue/167

Paperclip error

I am getting the following error when uploading an image on the admin panel of spree (RoR e-commerce platform):
Paperclip::NotIdentifiedByImageMagickError in Admin/imagesController#create
/tmp/stream.4724.0 is not recognized by the 'identify' command.
Any ideas? Thanks.
It sounds like the wrong identify command (which is part of ImageMagick) is being called (or, perhaps, it isn't installed at all). Can you confirm the path to this command on your server using:
which identify
Once you've determined where this command is installed (e.g. /usr/local/bin) then you can tell Paperclip about it by adding the following to your environment.rb (or production.rb etc) file:
Paperclip.options[:command_path] = '/usr/local/bin/'
(this is for Paperclip 2.2 and above. If you're using an earlier version you should use :image_magick_path not :command_path)
I solved this problem by
$ sudo apt-get install imagemagick
I'm not saying this is the solution but it wouldn't hurt to check your file permissions. Can the user running imagemagick access files in /tmp/ ?

Resources