... So We Built One
Sean Miller's old tech blog, to February 2009

2009-02-13: ImageScience, FreeImage, and Dreamhost PS

I wanted to use ImageScience (with the patch that adds support for rotation; ETA: now one-stop thanks to Dave Myron) to do some image manipulation in a Rails app, which I’m currently testing on a Dreamhost PS server.  ImageScience requires FreeImage, which loads on OS X easily with “sudo port install freeimage”, but on the PS server you can follow the instructions on the ImageScience page until you get to the point where you would execute “sudo make install”, which you can’t do.

Here’s my workaround:

1. On a local machine, get the FreeImage code:

cvs -z3 -d:pserver:anonymous@freeimage.cvs.sourceforge.net:/cvsroot/freeimage login
cvs -z3 -d:pserver:anonymous@freeimage.cvs.sourceforge.net:/cvsroot/freeimage co -D 2007-01-01 -P

2. Copy it across to the Dreamhost PS

3. On the Dreamhost PS:

make

4. Modify the Makefile.gnu file:

change:

INCDIR = /usr/include
INSTALLDIR = /usr/lib

to

INCDIR = {homedir}/.packages/include
INSTALLDIR = {homedir}/.packages/lib

and change:

install:
install -m 644 -o root -g root $(HEADER) $(INCDIR)
install -m 644 -o root -g root $(STATICLIB) $(INSTALLDIR)
install -m 755 -o root -g root $(SHAREDLIB) $(INSTALLDIR)
ln -sf $(SHAREDLIB) $(INSTALLDIR)/$(VERLIBNAME)
ln -sf $(VERLIBNAME) $(INSTALLDIR)/$(LIBNAME)
ldconfig

to:

install:
install -m 644 -o (your_user} -g {your_group} $(HEADER) $(INCDIR)
install -m 644 -o {your_user} -g {your_group} $(STATICLIB) $(INSTALLDIR)
install -m 755 -o {your_user} -g {your_group} $(SHAREDLIB) $(INSTALLDIR)
ln -sf $(SHAREDLIB) $(INSTALLDIR)/$(VERLIBNAME)
ln -sf $(VERLIBNAME) $(INSTALLDIR)/$(LIBNAME)

5. Run

make install

6. Since you don’t have direct access to ldconfig, add to the LD_LIBRARY_PATH in .bash_profile

export LD_LIBRARY_PATH="{homedir}/.packages/include:{homedir}/.packages/lib:$LD_LIBRARY_PATH"

7. Since Passenger won’t be going through your .bash_profile and seeing that LD_LIBRARY_PATH, also add it to your config/environment.rb file (further discussion here):

ENV['LD_LIBRARY_PATH']=”:{homedir}/.packages/include:{homedir}/.packages/lib”

Once that extended LD_LIBRARY_PATH is active, FreeImage will be accessible and ImageScience will work as expected.

Tags: ruby.