installing ImageScience an art?
By prashant on Mar 24, 2009
ImageScience is a pretty cool gem to use in your Rails application for Thumbnail generation. It doesn't install correctly out of the box since ImageScience uses an incorrect default path for locating FreeImage. The Makefile shipped with FreeImage also does not build correctly on OpenSolaris. So here's a way to make sure it works correctly first time if you are on OpenSolaris.
Step1: Update your Ruby package. We now package Ruby 1.8.7 p72 with OpenSolaris. Here is a blog entry I wrote sometime ago on how to upgrade to 1.8.7p72 -> http://blogs.sun.com/prashant/entry/how_does_one_update_ruby
Step2: Ensure that /usr/gnu/bin is prepended to your PATH environment variable. (or, just utter export PATH=/usr/gnu/bin:$PATH in bash).
Step3: Install the requisite OpenSolaris packages.
pfexec pkg install SUNWgmake
pfexec pkg install SUNWgnu-coreutils
The "pfexec" is there to give you enough privileges to install the packages. If you run as root(which I do - and which is not recommended), then you don't need to use pfexec.
Step4: Build FreeImage. Download it from http://downloads.sourceforge.net/freeimage/FreeImage3110.zip and unzip it. The Makefile that ships with FreeImage does not build correctly on OpenSolaris, so here is a Makefile that does -> http://blogs.sun.com/prashant/resource/files/Makefile.opensolaris .
Change directory into the exploded FreeImage source, and utter the following.
gmake -f Makefile.opensolaris
gmake -f Makefile.opensolaris install
Where Makefile.opensolaris is the OpenSolaris Makefile that you just downloaded.
Step5: The rbconfig.rb file in your Ruby installation needs to be changed. Edit this file(it's to be found in /usr/ruby/1.8/lib/ruby/1.8/i386-solaris2.11 )
Look for a line that goes thus:
CONFIG["LDSHARED"] = "ld -G"
and replace it with
CONFIG["LDSHARED"] = "$(CC) -G"
i.e., change the linker binary such that the GNU Linker is used by RubyInline(which is an ImageScience dependency).
This is a bug that will be fixed in build111. So if you have a newer version, this bug might already have been fixed.
Step6: Now install ImageScience the usual way.
gem install image_science
Step7: You should now be set. But, just to make sure, run the ImageScience tests and make sure they pass. Here is how to do that.
Edit $GEM_HOME/gems/image_science-1.1.3 test/test_image_science.rb (if you use the default gem home on OpenSolaris the file is to /var/ruby/1.8/gem_home/gems/image_science-1.1.3 test/test_image_science.rb ).
Add the following line to the beginning of the file.
Now test it by executing:
(or cd $GEM_HOME/gems/image_science-1.1.3 if your gem home is different).
ruby test/test_image_science.rbLoaded suite test/test_image_science
Finished in 0.01314 seconds.
7 tests, 28 assertions, 0 failures, 0 errors
And thats all it takes to have a working ImageScience library.