PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Martin San Juan  >  Resize Image Helper  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Resize Image Helper
Resize images with configurable aspect ratio
Author: By
Last change:
Date: 4 years ago
Size: 1,686 bytes


Class file image Download


// Raw Image Path
$path = "./img/01.jpg";

 * Load the image in the instance, but you can load the image after or reload
 * the image using $image->load_image($path);
$image = new Resize_image_helper($path);

 * Resize the image adjusting the width to 300px,
 * the height still the same

 * Resize the image adjusting the height to 300px,
 * the width still the same

 * At this point you have 3 images, the original image, other with the same name plus
 * a suffix "_w300" result of the first transform, and other with the suffix "_h300"
 * result of the second transform.
 * If you want changes applied to the original image and are cumulative
 * use the second parameter OVERWRITE = TRUE

 * Resize the image on both dimensions.
 * Create a new image with original name and the suffix _w500_h250.
 * You can use OVERWRITE = TRUE to apply the changes on the original image.
$image->resize_both(500, 250);

 * Change the aspect ratio.
 * The first element refers to the height and the second to the weight.
 * You can use OVERWRITE = TRUE to apply the changes on the original image.
 * The following aspects are the usual but you can use any you want.


 * You can clear the memory manually if you believe necessary, otherwise the image
 * resource be destroyed on the __destruct method.