ImageMagick


If you are using a plugin such as simple_captcha that requires RMagick, then you may encounter the following error during the rendering of jpeg catpcha image on Linux: (seen in the logs)

ArgumentError (unknown format: JPG):
/vendor/plugins/simple_captcha/lib/simple_captcha_image.rb:95:in `format=’

This mean that we need to install the delegate library for JPEG.
1. do apt-get install libjpeg62 (not sure if this is required or just dev is enough)
2. do apt-get install libjpeg62-dev
3. cd to where you downloaded Imagemagick and do ./configure, make, make install.
The result of ./configure will summarize the status of deletgate libraries in the end.

After this, a blank image should start to show up in place of the simple_catpcha image and the logs may show something like this:

sh: gs: command not found
sh: gs: command not found
RMagick: unable to read font `(null)’.
RMagick: Postscript delegate failed `/tmp/magick-XXfm5AzA’: No such file or directory.
sh: gs: command not found
sh: gs: command not found
RMagick: unable to read font `(null)’.
RMagick: Postscript delegate failed `/tmp/magick-XXg7z0RL’: No such file or directory.

4. Do apt-get install ghostscript if simple_captcha image shows up as a white blank image, without any letters. Don’t forget to do ./configure, make, make install from your Imagemagick source dir after this. Restarting of the server will be required for production environment.

Example result of ./configure status.

Delegate Configuration:
….
JPEG v1 –with-jpeg=yes yes
FreeType –with-freetype=yes yes

These 4 delegate libraries got simple_captcha working.
1. libfreetype6-dev (This also seems to be for fonts, but didn’t cut it for simple_captcha, but I had installed it already, so I let it be.)
2. libjpeg62-dev
3. libpng12-dev ( installed it just in case…)
4. ghostscript
Running ./configure, make, make install from imagemagick source dir is necessary after installing the above libraries.

If captcha image is not getting recognized, you may need to run the following (for rails > 2.0, there is a separate command for older Rails which can be seen from the simple_captcha website.)
rake simple_captcha:setup

then run
rake db:migrate

  1. The RMagick README asks you to update your Rubygems version to at least 0.9.4. The latest available version at this time is 0.9.5. But people have reported problems with RMagick installation using 0.9.5 version of RubyGems.
  2. I faced the same problem when I tried to install RMagick after updating my RubyGems version to 0.9.5. So I decided to install RubyGems 0.9.4 to be on the safe side and try insalling RMagick again. This was the status of installation of RMagick using RubyGems 0.9.5 “Successfully installed rmagick-1.15.9-unknown 1 gem installed.”
  3. Download rubygems-0.9.4.zip from RubyForge Ruby Gems. I downloaded it to C:\Softwares.
  4. Unzip rubygems-0.9.4.zip.
  5. cd to C:\Softwares\rubygems-0.9.4\rubygems-0.9.4. You should be able to see a file named setup.rb in this folder. On command prompt cd to this directory and key in: ruby setup.rb
  6. This installs 0.9.4 version of RubyGems.
  7. To double check the correct version of Ruby Gems key in (from any directory): gem –version and that should print 0.9.4
  8. We need to use the rmagick-win32 gem for installing RMagick on Windows. This gem is bundled with a a copy of the ImageMagick Windows installer so we don’t need to download our own copy.
  9. Download the rmagick-win32 gem from the RMagick project page on RubyForge and unzip it into a temporary directory.
  10. I downloaded RMagick-1.15.9_IM-6.3.5-8-Q8_prod.zip from RubyForge RMagick and saved it in C:\Softwares on my desktop.
  11. Unzipped RMagick-1.15.9_IM-6.3.5-8-Q8_prod.zip
  12. Unzipped RMagick-1.15.9.tar.zip that was inside RMagick-1.15.9_IM-6.3.5-8-Q8_prod
  13. Clicked on ImageMagick-6.3.5-8-Q8-windows-dll to install ImageMagick. This installs ImageMagick but I am not sure if we are supposed to install this manually or whether gem install rmagick will do it for us. Nonetheless, since I am a chicken, I installed it myself. This installer does not seem to interfere with an existing, different version of ImageMagick.
  14. To see the version of ImageMagick installed, key in: convert –version
  15. Now install the rmagick gem. C:\Softwares\RMagick-1.15.9_IM-6.3.5-8-Q8_prod> gem install rmagick-1.15.9-win32.gem –local This prints ‘Successfully installed rmagick, version 1.15.9′.
  16. I did not need to uninstall Ruby and install it through the one click installer. (What are you talking about?)
  17. Now restart your development server. ruby script/server
  18. There is no need to ‘require RMagick’ in your environment.rb or source code.
  19. Errors after installation of RMagick, on restarting the development server.
    “warning: already initialized constant OPTIONS > … ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:18:> undefined method `options’ for []:Array (NoMethodError)” This seems to be because of an error in RMagick installation. Key in: gem list on the command prompt to see if rmagick-win32 is indeed showing in the list. If not, you need to install RMagick.
  20. “Procedure entry point HSL transform could not be located in the dynamic link library CORE_RL_magick.dll” OR “CORE_RL_magick.dll not found”. For CORE_RL_magick.dll problems you can do 2 things:
    check if ImageMagick is correctly installed. If there are any other installations of ImageMagick installed, it might be better to uninstall them.Restart your Windows machine. Yes, not the development server, but your computer. This makes available all the paths to ImageMagick. This tip, courtesy: http://www.texxors.com/?p=24. To make sure if this is indeed the problem, key in: convert –version on a path not in ImageMagick\bin folder (where convert.exe) resides. If it complains of invalid drive etc. you know that the path to ImageMagick is not being recognized. Restarting the machine helps correct this problem. After restarting, if you key in: convert –version, you should be able to see: Version: ImageMagick 6.3.5 09/01/07 Q8 http://www.imagemagick.orgcopyright/: Copyright (C) 1999-2007 ImageMagick Studio LLC

Follow

Get every new post delivered to your Inbox.