Installing ImageMagick with JPEG, TIFF and PNG Support

I really like ImageMagick, as I think I've mentioned before. It produces much better images than GD does and still isn't a resource hog, which puts it on my Must Have list. I use ImageMagick on several of my own sites via PHP so it's on all of my servers. This means people I host get the advantage of having it available too.

The only problem is that the default installation of ImageMagick will usually only support converting .gif images. Many times this is because of what the server itself supports natively. So every time I get a new server I have to remember what to install and how to install ImageMagick so that it'll support more image formats. I just had to do that (again) and suspect that others run into the same issue all too often, so following is a quick and dirty tutorial how to do it.

Note: This is for a *nix system (RedHat Enterprise to be more exact) but should work with almost any installation, excepting a Windows server.

First, if it's a new server that's never had ImageMagick installed before, you're likely going to need some additional files. Otherwise it simply won't work.

Second, I'm assuming you have Root access to the server via SSH.

Third, if you've previously tried to make or install ImageMagick, you're going to want to undo that. If you don't, you'll run into problems. Trust me on this one. So if you've already tried to install ImageMagick before finding these instructions navigate to the Source directory where you downloaded IM and type in: make uninstall

Okay, now we're ready to start.

The additional files you'll need are the libs for jpeg, png, tiff and lzw compression. You can check if they're already installed, or you can just install them. On a *nix system the header files should be stored in /usr/include and/or /usr/local/include. The files you'll be looking for are named:

tiff.h
png.h
jpeglib.h

If you have 'em all already you can skip some of the downloads below, though you may also choose to re-install them to make sure your libs are resonably up to date. The files you'll need are uploaded to my server here. They are:

ImageMagick-6.2.3-0.tar.gz (Though you should also be able to use the most recent version from ImageMagick's site)
jpegsrc.v6b.tar.gz
libpng-1.0.6.tar.gz
libtiff-lzw-compression-kit-1.1.tar.gz
tiff-v3.5.5.tar.gz

If you download these to your computer and then upload them to your server via FTP make sure you do so in Binary mode. ASCII transfers will break the files.

Or, if you would prefer to download them directly to your server, SSH in and go to the directory where you keep stuff you've downloaded (/usr/local/src for me) and run the fullowing:

wget http://www.randycullom.com/ImageMagick/ImageMagick-6.2.3-0.tar.gz
wget http://www.randycullom.com/ImageMagick/jpegsrc.v6b.tar.gz
wget http://www.randycullom.com/ImageMagick/libpng-1.0.6.tar.gz
wget http://www.randycullom.com/ImageMagick/libtiff-lzw-compression-kit-1.1.tar.gz
wget http://www.randycullom.com/ImageMagick/tiff-v3.5.5.tar.gz

Next we need to unzip and uncompress each of the files. So:

tar -zxvf ImageMagick-6.2.3-0.tar.gz
tar -zxvf jpegsrc.v6b.tar.gz
tar -zxvf libpng-1.0.6.tar.gz
tar -zxvf libtiff-lzw-compression-kit-1.1.tar.gz
tar -zxvf tiff-v3.5.5.tar.gz

Now let's start installing stuff.

Type:
cd libpng-1.0.6/scripts

Now do an "ls" to look for the makefile that matches your operating system. On all of my systems this is going to be one called makefile.linux, but choose the one that matches your system. If you don't see a file included for your operating system --and it's not a *nix system-- your best bet is to try to makefile.gcc file.

Let's copy our makefile to a location we can use it. So in my case I would type:
cp makefile.linux ../makefile

And install libpng by typing:
cd ..
make
make install

Now let's move on to jpeg support. Type:
cd ..
cd jpeg-6b
./configure --enable-shared
make
make install

Next up is lzw compression support. Type:
cd ..
cd libtiff-lzw-compression-kit

We need to make a small edit to the Makefile to make our lives easier. Normally you would do this either with nano, pico or vi. If you use nano or pico make sure you always use the -w option. I use nano, like:
nano -w Makefile

Change the line that reads:
TIFF_SRC_DIR = /tmp/libtiff

so that it reads:
TIFF_SRC_DIR = ../tiff-v3.5.5

Exit your editor, saving the changes. Then type:
make install
cd ..
cd tiff-v3.5.5
./configure

Answer yes to the TIFF Configuration Parameters. When it's done type:
make
make install

Finally, let's install ImageMagick. Type:
cd ..
cd ImageMagick-6.2.3
./configure --enable-lzw=yes --enable-shared=yes --disable-static --without-perl
make
make install

That's it! You should now have ImageMagick installed, with support for .gif, .jpg/jpeg, .png and .tiff file types. You can test it right from your SSH command line. ImageMagick comes with a test image that will produce an error if it experiences a problem. To test things out type the following:
/usr/local/bin/convert logo: logo.gif
/usr/local/bin/convert logo: logo.jpg
/usr/local/bin/convert logo: logo.png
/usr/local/bin/convert logo: logo.tiff

You shouldn't see any errors. And when you do an ls you should see your four new files listed.

[Added for Nick's question in the comments below.]
The currently available original source(s) of the image library files can be found at:

The Independent JPEG Group
The LibPNG Reference Library
The LibTIFF/TIFF Library
and of course...
The ImageMagick site for the IM source files

I keep them all here because it's easier than directing people to multiple places so that one ends up with a final application that works. Plus I use 'em myself when I need to install IM on a new server. But by all means feel free to grab the updated versions from the above places, as long as you don't mind the possibly of having to work through a few niggling issues to get it all working properly.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章