PHP Classes

File: image_example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of Marcos Taranta  >  HolyImage  >  image_example.php  >  Download  
File: image_example.php
Role: Example script
Content type: text/plain
Description: Example usage of the Image class
Class: HolyImage
Resize images of different formats
Author: By
Last change: Added the contents
Date: 6 years ago
Size: 1,815 bytes


Class file image Download


 * The constructor of the class get the type of the file being suplied to it and use the correct function of GD library
 * to create the image in the memory.
 * In this example we will be loading a JPEG image, for a PNG or GIF image the command is the same, just suply the filename
 * and the class take care of the correct command for the extension.
 * If the extension of the file is unsupported, the class will throw a ErrorException!
$image = new Image("Sunset.jpg");

 * So lets say you want to resize the image and maintain the aspect of the image, in case you want an especific width and height
 * the class will crop the equaly the sides of the image (verticaly or horizontaly, depends on the final aspect you want based on the
 * width and height you want) and resample the image to the desired width and height!
 * In case you only want a desired width, you can use the resampleProportionWidth or for the height resampleProportionHeight method.
 * In case you only want to resample, without caring the aspect of the final image just use resample method!
$image->resampleCropProportion(200, 150);

 * For outputing the image, we will be converting the image to PNG and outputing to a file with a quality (in case of PNG
 * the quality parameter is used as compression) of 9, and will be outputing to a file but we can just output it on the
 * screen just by supling a NULL filename parameter!
 * The class also defines some constants for the types of the images that can be suplied in the first parameter, but you
 * can also suply the mimetype as a string!
$image->output(PNG, "new_sunset.png", 9);

 * Let's just show as HTML the new image to see what happened!
echo "<img src=\"new_sunset.png\" />";