RMagick at DreamHost
Ruby users can use RMagick to access the image processing functionality of ImageMagick.
The versions installed at DreamHost are well behind the current releases, and lack many of the newer features, and most critically, much needed bug fixes.
You can install your own versions to get around this limitation.
- Install your own version of ImageMagick, following the configuration instructions as given at Compiling ImageMagick
- This may take a few attempts, as it is very CPU intensive when running the tests, and this apparently causes DreamHost to periodically kill the build.
- If you're only planning on using ImageMagick for RMagick, you can save a little time and disk space by using the
--without-magick-plus-plusoptions when configuring the ImageMagick build. This disables PerlMagick and Magick++.
- Be sure to include these configuration options:
- After installing ImageMagick
cd ~and set the paths for the binary and libraries. With these settings you'll be able to use RMagick under FastCGI without needing to work around the LD_LIBRARY_PATH environment variable:
$ export PATH=$HOME/local/bin:$PATH $ export LDFLAGS=-L/$HOME/local/lib $ export CPPFLAGS=-I/$HOME/local/include $ export LD_RUN_PATH=$HOME/local/lib $ export PKG_CONFIG_PATH="$HOME/local/lib/pkgconfig"
- Create your own gems repository
- Set your gems environment
- Set environment variable
export GEM_PATH=$HOME/gems:/usr/local/lib/ruby/gems/1.8; export GEM_HOME=$HOME/gems
- Configure ~/.gemrc (a YAML format file):
- Set environment variable
gemhome: /home/<user>/gems gempath: - /home/<user>/gems - /usr/local/lib/ruby/gems/1.8
- Make sure your .bash_profile is sourced (
source ~/.bash_profile) if your paths are in there. Double-check /local/bin is in your path with
- Download the gem file and install it from the downloaded copy. Dreamhost seems to kill the process when trying to install from remote.
$ cd ~/src $ wget 'http://rubyforge.org/frs/download.php/70065/rmagick-2.13.1.gem' $ gem install -l rmagick-2.13.1.gem -- --build-opts --prefix=$HOME/local
Now, you have a personal version of ImageMagick and of RMagick. To reference them, there are these additional steps:
- Update code to explicitly use the right version of the gem. Add this line to modules requiring RMagick support:
require_gem 'rmagick', '>= 2.13'
If your server has been upgraded to rubygems 0.9.0.8 or later (gem --version) use these lines instead, as require_gem is deprecated:
gem 'rmagick', '>= 2.13' require 'RMagick'
- For direct invocations of Ruby (including BackgrounDRB), be sure that the environment is set up (like GEM_PATH) before starting the Ruby process.
- For Rails invocations, set GEM_PATH in your environment.rb file, before running the Initializer (where the ENV['RAILS_ENV'] line is)
ENV['GEM_PATH'] = "/home/<user>/gems:/usr/local/lib/ruby/gems/1.8"
You can also try locking your gems for your application with
I found that installing the gem failed with:
checking for wand/MagickWand.h... no Can't install RMagick 2.X.X. Can't find MagickWand.h.
This failed even if I provided the --with-opt-dir configuration option. It was fixed by setting the PKG_CONFIG_PATH environment variable as follows:
Installed Versions Adequate (5/25/2007)
I (Edwin) find that the installed versions of ImageMagick and its (Ruby wrapper) RMagick to be adequate for my current needs, so I didn't perform my own installations of either.
To check the versions from the command interface:
convert -version (displays ImageMagick version) ls -d /usr/lib/ruby/gems/1.8/gems/rmagick* (displays all installed RMagick gems)
My Rails app -- which worked properly under InstantRails (Windows) -- did yield an "uninitialized constant Magick" error, because I omitted the "require 'RMagick'" line. Changing the relevant source to the following fixed the problem:
require 'rubygems' # ensure that the gem package is available gem 'rmagick', '>=1.12.0' # Add the rmagick gem to the module search path require 'RMagick' # Load RMagick.rb or RMagick.so