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: 11 years ago
Size: 1,686 bytes
 

Contents

Class file image Download
<?php

require_once("./classes/resize_image_helper.php");

// 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
 */
$image->resize_width(300);

/*
 * Resize the image adjusting the height to 300px,
 * the width still the same
 */
$image->resize_height(300);

/*
 * 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.
 */

$image->change_aspect_ratio("1:1");
$image->change_aspect_ratio("4:3");
$image->change_aspect_ratio("3:2");
$image->change_aspect_ratio("16:9");
$image->change_aspect_ratio("3:1");

/*
 * You can clear the memory manually if you believe necessary, otherwise the image
 * resource be destroyed on the __destruct method.
 */
$image->free_image_mem();

?>