Name | Modified | Size | Downloads / Week |
---|---|---|---|
readme.md | 2012-01-07 | 3.7 kB | |
zebra_image.2.2.1.zip | 2012-01-07 | 176.7 kB | |
zebra_image.2.1.zip | 2011-02-05 | 175.1 kB | |
zebra_image.2.0.zip | 2011-01-04 | 20.0 kB | |
Totals: 4 Items | 375.5 kB | 0 |
Zebra_Image, a lightweight image manipulation library written in PHP
This is a compact (one-file only), lightweight, object-oriented image manipulation library written in and for PHP, that provides methods for performing several types of image manipulation operations. It doesn’t require any external libraries other than the GD2 extension (with which PHP usually comes pre-compiled with).
With this library you can rescale, flip, rotate, crop and sharpen images. It supports loading and saving images in the GIF, JPEG and PNG formats and preserves transparency for GIF, PNG8 and PNG24 images.
Zebra_Image‘s code is heavily commented and generates no warnings/errors/notices when PHP’s error reporting level is set to E_ALL.
Requirements
PHP 4.4.9+, bundled GD 2.0.28+
Installation
Download the latest version, unpack it, and put it in a place accessible to your scripts.
How to use
<?php
// load the image manipulation class
require 'path/to/Zebra_Image.php';
// create a new instance of the class
$image = new Zebra_Image();
// indicate a source image (a GIF, PNG or JPEG file)
$image->source_path = 'path/to/image.png';
// indicate a target image
// note that there's no extra property to set in order to specify the target image's type -
// simply by writing '.jpg' as extension will instruct the script to create a 'jpg' file
$image->target_path = 'path/to/image.jpg';
// since in this example we're going to have a jpeg file, let's set the output image's quality
$image->jpeg_quality = 100;
// some additional properties that can be set
// read about them in the documentation
$image->preserve_aspect_ratio = true;
$image->enlarge_smaller_images = true;
$image->preserve_time = true;
// resize the image to exactly 100x100 pixels by using the "crop from center" method
// (read more in the overview section or in the documentation)
// and if there is an error, check what the error is about
if (!$image->resize(100, 100, ZEBRA_IMAGE_CROP_CENTER)) {
// if there was an error, let's see what the error is about
switch ($image->error) {
case 1:
echo 'Source file could not be found!';
break;
case 2:
echo 'Source file is not readable!';
break;
case 3:
echo 'Could not write target file!';
break;
case 4:
echo 'Unsupported source file format!';
break;
case 5:
echo 'Unsupported target file format!';
break;
case 6:
echo 'GD library version does not support target file format!';
break;
case 7:
echo 'GD library is not installed!';
break;
}
// if no errors
} else {
echo 'Success!';
}
?>