PHP Classes

File: fitin.pimg.php

Recommend this page to a friend!
  Classes of Tony Bogdanov  >  PIMG  >  fitin.pimg.php  >  Download  
File: fitin.pimg.php
Role: Class source
Content type: text/plain
Description: Fitting an image in a rectangle
Class: PIMG
Process images using multiple operations
Author: By
Last change: 1.1
Date: 11 years ago
Size: 1,170 bytes
 

Contents

Class file image Download
<?php
/* PIMG module: resizes an image keeping it's aspect ratio and fits it in an user defined rectangle */
class pimg_fitin
{
   
/* Resources */
   
private $pimg;
   
   
// PIMG constructor
   
function __construct($pimg)
    {
       
$this -> pimg = $pimg;
    }
   
   
   
   
/*
        Resizes an image keeping it's aspect ratio and fits it in an user defined rectangle
        @param: $width - rectangle width
        @param: $height - rectangle height
        @result: a pointer to the caller pimg class for furthur usage
    */
   
function init($width, $height)
    {
       
/* INPUT VALIDATORS */
       
if ($width <= 0)
           
$this -> pimg -> setDebug('Fitin destination width must be > 0', 'error', __CLASS__);
        if (
$height <= 0)
           
$this -> pimg -> setDebug('Fitin destination height must be > 0', 'error', __CLASS__);
       
       
// Callculate new width and height
       
$newWidth = $width;
       
$newHeight = $this -> pimg -> height() * $newWidth / $this -> pimg -> width();
       
        if (
$newHeight > $height)
        {
           
$newHeight = $height;
           
$newWidth = $this -> pimg -> width() * $newHeight / $this -> pimg -> height();
        }
       
       
// Resize
       
return $this -> pimg -> stretch($newWidth, $newHeight);
    }
}
?>

For more information send a message to info at phpclasses dot org.