| 
<?php
/* PIMG module: resizes an image by stretching it to e specified width and height */
 class pimg_stretch
 {
 /* Resources */
 private $pimg;
 
 // PIMG constructor
 function __construct($pimg)
 {
 $this -> pimg = $pimg;
 }
 
 
 
 /*
 Resizes the image by stretching it to a specified width and height
 @param: $width - integer value
 @param: $height - integer value
 @result: a pointer to the caller pimg class for furthur usage
 */
 function init($width, $height)
 {
 /* INPUT VALIDATORS */
 if ($width <= 0)
 $this -> pimg -> setDebug('Width must be > 0', 'error', __CLASS__);
 if ($height <= 0)
 $this -> pimg -> setDebug('Height must be > 0', 'error', __CLASS__);
 
 // If width and height are the same as original skip the stretching
 if ($this -> pimg -> width() != $width || $this -> pimg -> height() != $height)
 {
 // Create a new empty image
 $resized = $this -> pimg -> newImage(null, $width, $height);
 
 // Resize the original
 imagecopyresampled($resized, $this -> pimg -> handle(), 0, 0, 0, 0, $width, $height, $this -> pimg -> width(), $this -> pimg -> height());
 
 // Update the pimg class
 $this -> pimg -> update($resized, $width, $height);
 }
 
 // Return the caller pimg instance
 return $this -> pimg;
 }
 }
 ?>
 |