The php class imagickLib uses ImageMagick to manipulate images.
Written by Oliver Kührig, viersicht (http://www.viersicht.de)
At the beginning you have to load and instantiate the class. After these steps load the image, make as many "actions" as you want and finally save it to a new file.
Here we read the file "Bambus.jpg", resize it and save it into a new file.
// include the class file (required) include('class.imagickLib.php'); // make a instance of the class (required) $l_oImageMagick = new imagickLib(); // image input by file $l_oImageMagick->input("file", "./img/Bambus.jpg"); // resize the image to max. 400px width and max. 300px height $l_oImageMagick->actionResize(400, 300); // image output into file named "testpic0" $l_oImageMagick->output("file", "testpic0");
Locate the binary files of ImageMagick. By default it is "/usr/bin/".
var $imageMagickDir = '/usr/bin/'; // ImageMagick binary files
Enable or disable logging. Define the logfile-path and file. The file needs write permission by the webserver.
var $log = true; // write log file, if true var $logDir = './'; // logfile dir var $logFile = 'imagickLib.log'; // logfile name
imagickLib produces temporary file. Define the temporary directory to store them. In the end the files will be deleted by the "cleanUp"-method.
var $tempDir = '/var/tmp/'; // httpd must be able to write there
Defines the default directory to store the resulting images. Can be changed while using the class.
var $targetDir = './'; // target dir for the result picture
Defines the JPG-Quality
var $jpgQuality = '65'; // quality for JPG images
To produce small image-files, strip all profile informations for example exif data. You have to perform at least one "actionConvert()"
var $stripProfile = true; // if set to true on conversion image profile information will be stripped
The input-method knows three possibilities to load images:
$l_oImageMagick->input("file", "./img/Bambus.jpg"); $l_oImageMagick->input("binary", file_get_contents("./img/Bambus.jpg")); $l_oImageMagick->input("http", "http://www.example.com/Bambus.jpg");
To get the produced image you can use two ways:
$l_oImageMagick->output("file", "testpic0"); $l_oImageMagick->output("binary");
The class provides you different methods to manipulate images.
Blur the image with a gaussian operator. Define the radius as first and the sigma as second parameter.
$l_oImageMagick->actionBlur(5, 2);
Resize the image to given size. Make a transpanrent border around the image to fit the size. The direction parameter defines the position of the filling image.
$l_oImageMagick->actionBorder(400, 300, 'north');
Converts the picture in a new format. Possible values are 'jpg', 'png', 'gif', 'bmp', ...
$l_oImageMagick->actionConvert("png");
Crops the image to given size. The example crops the image at center 100x100 pixel.
Third parameter:
$l_oImageMagick->actionCrop(100, 100, 'center');
Flips the image "horizontal" (default) or "vertical"
$l_oImageMagick->actionFlip('vertical');
Draws a frame around the image with a width (default=5) and a color (default="666666")
$l_oImageMagick->actionFrame(6, "FF0000");
Create soft fuzzy shadows
$l_oImageMagick->actionFuzzyShadow();
Converts the image to grayscale
$l_oImageMagick->actionGrayscale();
Labels the image. Produce a alpha-transparent gray background with white text.
$l_oImageMagick->actionLabel("Testlabel Test2 Test3 Test4", "south");
Produce many polaroid images with random rotation.
$l_oImageMagick->actionManyPolaroids();
Converts the image to monochrome (2 color black-white)
$l_oImageMagick->actionMonochrome();
Converts the image to negative
$l_oImageMagick->actionNegate();
Polaroid-like image with white border, a shadow, rotation. The parameter defines the rotation in degrees.
$l_oImageMagick->actionPolaroid(-6);
Resize the image to given size. Third parameter defines the method:
$l_oImageMagick->actionResize(400, 300);
Rotates the image by given degree. Second optional parameter defines the color in background (default is white). The third parameter:
$l_oImageMagick->actionRotate(30);
Square the image by to different methods:
$l_oImageMagick->actionSquare('border', 'FFA200');
After all is done, you should perform the cleanUp-method to delete all temporary files.
$l_oImageMagick->cleanUp();
Go steps back and virtually delete actions. The parameter defines the amount of actions to revoke (default is 1). In this example we undo the crop-action.
include('class.imagickLib.php'); $l_oImageMagick = new imagickLib(); $l_oImageMagick->input("file", "./img/Bambus.jpg"); $l_oImageMagick->actionGrayscale(); $l_oImageMagick->actionCrop(100, 100, 'center'); $l_oImageMagick->output("file", "testpic0"); $l_oImageMagick->goBackInAction(1); $l_oImageMagick->actionFrame(1, "000000"); $l_oImageMagick->actionFuzzyShadow(); $l_oImageMagick->output("file", "testpic1"); $l_oImageMagick->cleanUp();
For debug-purpose use the printError-method to print errors.
$l_oImageMagick->printError();