Getting started

PHP Image Magician has been designed to be easy to setup and use. Following these steps should get you on your way!

Step 1 - Download PHP Image Magician

You can download PHP Image Magician from the home page

Step 2 - Extract

Extract the content of the downloaded archive to a location in your PHP project.

Step 3 - Include library

You need to include the PHP Image Magician library in your PHP page.


You're now ready to use PHP Image Magic. Click here to continue.



The resize method allows you to resize your images in a variety of ways, depending on your needs. Firstly, you can resize an image to an exact width and height. This is useful if you know the original image ratio, otherwise distortion will occur.

A solution to preventing distortion is to use one of the clever resizing options such as landscape or portrait. The landscape option will resize the image to the width you specify and the height will be calculated automatically to maintain the image proportions. The Portrait option is the same but it's the height you specify that is used while the width is calculated.

But what if the image is uploaded by a user and we don't know if it's landscape or portrait? We've thought of that, too! auto mode will determine the images orientation and resize the image appropriately using either landscape or portrait automatically.

The last option in our bag of tricks is the crop option. This will resize the image as close as it can to the size you specified, while still maintaining the aspect ratio, then crop the rest. This is extremely useful for creating images, such as thumbnails, that are all the same size and don't have distortion!


	$imageLibObj -> resizeImage($width, $height, $option=0, $sharpen=false);
  • $width: The width to resize your image to
  • $height: The height to resize your image to
  • $option (default: 'exact'): The type of resize you wish to perform. You can either the numerical or textual value when defining the option:
Option Description
0 or exact (default) The width to resize your image to.
1 or portrait Keep aspect. The height you set will be used. The width will be calculated and set automatically to a value that retains the aspect ratio.
2 or landscape Keep aspect. The width you set will be used. The Height will be calculated and set automatically to a value that retains the aspect ratio.
3 or auto Determine best option. Depending whether the image is landscape or portrait, this will automatically determine whether to resize via 'exact', 'portrait', or 'landscape'. This is useful when you have no control over whether the image to be resized will be landscape or portrait.
4 or crop Resize and crop. Will resize the image and then crop the image for the best fit, making the image the exact size you specify.
  • $sharpen (default: false): Apply subtle sharpening to make your image standout.
Exact resize
	$imageLibObj -> resizeImage(100, 200, 'exact');
Crop option
	$imageLibObj -> resizeImage(100, 200, 'crop');
Landscape option
	$imageLibObj -> resizeImage(100, 200, 'landscape');
	$imageLibObj -> resizeImage(100, 200, 'true');

Resize With the Crop Option

PHP Image Magician gives you the ability to select the crop position, rather than defaulting to a center crop.

To do this, you need to pass the crop resize option as an array. The first element being the crop option, the second being the crop position.


	$imageLibObj -> resizeImage(100, 200, array('crop', 'tl'));

tl stands for "top-left". After the image has been resized, the crop position will now be the top left corner. See the table below for other values.

Instead of passing an array with the option, you can pass a hyphenated string. The first part of the string is "crop" followed by the position which is separated by a hyphen.


	$imageLibObj -> resizeImage(100, 200, 'crop-tl');

The above two examples are both valid and will produce the same result.

shortcode Description
tl top left
t top (middle)
tr top right
l left
m middle (image center)
r right
bl bottom left
b bottom (middle)
br bottom right
auto If the image is landscape, the image will be cropped in the center. If the image is portrait, the image will be cropped 10% (default) from the top of the image. This is useful when the images are of people as their heads are usually in the top portion of the photo.

You can change the percentage from the top with the setCropFromTop() method. E.G., setCropFromTop(20);

Crop (no resize)

You can apply a crop to an image without having to resize it first.

  • $width: The width to crop your image to
  • $height: The height to crop your image to
  • $cropPos (default: 'm'): See the crop options table for more values.

	$imageLibObj -> cropImage($width, $height, $cropPos = 'm');


To apply a vintage look:

	$imageLibObj -> vintage();
Exact resize
$imageLibObj -> vintage();


There are 3 greyscale effects that can be applied. The first is the basic stock standard GD greyscale, the second is an enhanced version adding in some contrast. And lastly there is the dramatic greyscale effect.

Greyscale basic

	$imageLibObj -> greyScale();
Greyscale enhanced

	$imageLibObj -> greyScaleEnhanced();
Greyscale dramatic

	$imageLibObj -> greyScaleDramatic();
Greyscale basic
	$imageLibObj -> greyScale();
Greyscale enhanced
	$imageLibObj -> greyScaleEnhanced();
Greyscale dramatic
	$imageLibObj -> greyScaleDramatic();

Note: With Greyscale dramatic use an image 950 x 650px or smaller for best results.

More coming soon!