BlogimageModifier: a PHP Class for manipulating images
imageModifer is a PHP class that allows you to crop and resize images. The following formats are supported:
- PNG
- JPG
- GIF
This class requires PHP 5 and GD2 Library (GD2 with GIF support if you want to modify GIF images).
Download
imageModifier.class.php (9.5kb)
Docs: Functions
__construct
__construct ($imagePath, $memoryIncrease = false)
string $imagePath
This is the path to the image you wish to manipulate.
string $memoryIncrease
If you are trying to modify large images, this allows you to set the memory limit higher. Only set it as high as you know will work because if you set it too high it will revert to 8M which isn’t very much. For most hosts, try 30M. False will leave it at the default.
crop
crop ($output, $width, $height, $cx = 0, $cy = 0)
string $output
This is the location where you want to save the outputted image.
int $width
The width of the crop.
int $height
The height of the crop.
int $cx
The x location on the source image where you want to start the crop.
int $cy
The y location on the source image where you want to start the crop.
centerImageOnCanvas
centerImageOnCanvas ($output, $image, $canvas_w, $canvas_h, $bg, $opac)
string $output
This is the location where you want to save the outputted image.
string $image
Path to the source image. Use $this->path to use the image you initialized the class this.
int $canvas_w
The width of the canvas you wish to center the image on.
int $canvas_h
The height of the canvas you wish to center the image on.
array $bg
An array with 3 integers corresponding to the Red Green and Blue (RGB).
int $opac
1-127 scale of opaque to transparent background (used only on PNG images)
resize
resize ($output, $maxwidth, $maxheight, $quality=100)
string $output
This is the location where you want to save the outputted image.
int $maxwidth
The width you want to resize to.
int $maxheight
The height you want to resize to.
int $quality
1-100 scale of quality for JPEG images.
Comment Guidelines