PHP Classes

File: crop.pimg.php

Recommend this page to a friend!
  Classes of Tony Bogdanov   PIMG   crop.pimg.php   Download  
File: crop.pimg.php
Role: Class source
Content type: text/plain
Description: Class for cropping images
Class: PIMG
Process images using multiple operations
Author: By
Last change: 1.1
Date: 13 years ago
Size: 1,420 bytes
 

Contents

Class file image Download
<?php
/* PIMG module: replaces the original image with a cropped rectangle */
class pimg_crop
{
   
/* Resources */
   
private $pimg;
   
   
// PIMG constructor
   
function __construct($pimg)
    {
       
$this -> pimg = $pimg;
    }
   
   
   
   
/*
        Replaces the original image with a cropped rectangle specified by it's start point's X & Y and width, and height
        @param: $x - x of start point
        @param: $y - y of start point
        @param: $width - width of rectangle
        @param: $height - height of rectangle
        @result: a pointer to the caller pimg class for furthur usage
    */
   
function init($x, $y, $width, $height)
    {
       
/* INPUT VALIDATORS */
       
if ($x < 0)
        {
           
$x = 0;
           
$this -> pimg -> setDebug('X start point must be >= 0', 'notice', __CLASS__);
        }
        if (
$y < 0)
        {
           
$y = 0;
           
$this -> pimg -> setDebug('Y start point must be >= 0', 'notice', __CLASS__);
        }
        if (
$width <= 0)
           
$this -> pimg -> setDebug('Crop width must be > 0', 'error', __CLASS__);
        if (
$height <= 0)
           
$this -> pimg -> setDebug('Crop height must be > 0', 'error', __CLASS__);
       
       
// New empty image
       
$crop = $this -> pimg -> newImage(null, $width, $height);
       
       
// Crop the area
       
imagecopy($crop, $this -> pimg -> handle(), 0, 0, $x, $y, $width, $height);
       
       
// Update the image
       
$this -> pimg -> update($crop, $width, $height);
       
       
// Return the caller pimg instance
       
return $this -> pimg;
    }
}
?>