Login   Register  
PHP Classes
elePHPant
Icontem

File: fitout.pimg.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Tony Bogdanov  >  PIMG  >  fitout.pimg.php  >  Download  
File: fitout.pimg.php
Role: Class source
Content type: text/plain
Description: Fitting an image out a rectangle
Class: PIMG
Process images using multiple operations
Author: By
Last change: 1.1
Date: 2010-10-31 18:37
Size: 1,175 bytes
 

Contents

Class file image Download
<?php
/* PIMG module: resizes an image keeping it's aspect ratio and fits it out an user defined rectangle */
class pimg_fitout
{
    
/* Resources */
    
private $pimg;
    
    
// PIMG constructor
    
function __construct($pimg)
    {
        
$this -> pimg $pimg;
    }
    
    
    
    
/*
        Resizes an image keeping it's aspect ratio and fits it out 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('Fitout destination width must be > 0''error'__CLASS__);
        if (
$height <= 0)
            
$this -> pimg -> setDebug('Fitout 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);
    }
}
?>