KNOW:
How to setup a LAMP Webserver in either CentOS or Ubuntu
How to program in PHP
Actually have a need for this library for viewing graphic images.
What is Imagick???
Imagick, a horrible name by the way, is a great alternative to the built in GD library supplied by PHP for viewing images. It's much faster and more structured.
Sadly the documentation to install the software is PAINFUL and lacking. I checked many a forums and blogposts for a variety of BAD information. It's amazing.
Anyway, let's figure out how to do it.
Please note I am using repositories rather than download from source as I hate involving those headaches. I'd rather have others instead. These have been tested with the OS in question and I personally recommend that approach
CentOS: (for old-outdated version)
By far the most work. If you want to use the CentOS repositories, I have set this up as a script for you. This should work just fine but I honestly don't recommend it. Imagick is horribly out of date with many basic functions not even included.
!#/bin/bash
yum install ImageMagick.386 -y
# need to investigate. Do we need the devel.
yum install ImageMagick-devel.386 -y
# you need this and pear for the next two steps.
yum install gcc gcc-c++ autoconf automake -y
yum install pear -y
# update the pear channel
pecl channel-update pecl.php.net
# use pear to install it
pecl install imagick -y
# make a new file called imagick.ini and have one line in it to alert php of this new feature
# It will not work installing in php.ini
echo 'extension=imagick.so' > /ect/php.d/imagick.ini
service httpd restart
# just to test it from the command line
php -m | grep imagick
BUT WAIT!!!!!!!!!!!!!!
This version of Imagick ??? You might as well have downloaded the Model-T.
TRICKY!!!!
The easiest way is to simply use a repository. REMI is an excellent repository for the most up-to-date RPM's for CentOS Keep in mind that you now will deal with two repositories so their are some basic bookkeeping issues here.
1) ALWAYS use -- enablerepo=remi --disablerepo=* when dealing with this repo for installing and removing packages.
2) Be sure to think about integrated packages. In this case we need both php AND Imagick so we will be getting both. You can live with the old versions of Mysql and Apache as they won't conflict.
Now, here's the messy ugly steps you need to do.
As of 2013 this is the valid link
#!/bin/bash
# get the data to support REMI Link is valid for 2013
wget http://rpms.famillecollet.com/enterprise/remi.repo
# tell YUM to enable the repo
yum --enablerepo=remi
# remove your current outdated version of PHP. VERY IMPORTANT as we don't want library conflicts.
yum remove php
# Install php and ImageMagik and pear
# NOTE --disablerepo=* we disable EVERY repo for PHP and just use REMI otherwise
# messy dependency issues reveal its ugly head
yum install --disablerepo=* php ImageMagick2 php-pecl-imagick --enablerepo=remi
# restart apache
service restart httpd
# php -m | grep imagick
Ubuntu 12.04 (somewhat easier right :)
!#/bin/bash
apt-get install imagemagick libmagickcore-dev -y
apt-get install php-5-imagick -y
You went through all that work and I'm not showing you how to test it. That's not nice. Here's a quick and dirty test file you can generate. I called my Test.php since I was in a hurry.
<?php
$FullPathName = '(put your test image here. I'd recommend using the full path ';
// setup a new image and import from file.
$Image = new Imagick ($FullPathName);
// generate a header for display
header('Content-type: image/jpeg');
// If 0 is provided as a width or height parameter,
// // aspect ratio is maintained
$Image->thumbnailImage (100, 0);
//
echo $Image;
//
die ();
?>
No comments:
Post a Comment