PHP Classes

File: stretch.pimg.php

Recommend this page to a friend!
  Packages of Tony Bogdanov   PIMG   stretch.pimg.php   Download  
File: stretch.pimg.php
Role: Class source
Content type: text/plain
Description: Class for stretching an image
Class: PIMG
Process images using multiple operations
Author: By
Last change: 1.1
Date: 16 years ago
Size: 1,318 bytes
 

Contents

Class file image Download
<?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;
    }
}
?>