<?php
/******************************************************************************
* File : $RCSfile: class.imagecontainer.php,v $
* Project : pdfDOM
* Description : Container object
* Author : Timo A. Hummel <hide@address.com>
* Created : 29.01.2003
* Modified : $Date: 2005/06/23 13:36:22 $
*
* This file is part of the pdfDOM project.
*
* More information:
* http://www.pdfdom.org
* http://www.sf.net/projects/pdfdom
*
* © four for business AG, www.4fb.de
*
* $Id: class.imagecontainer.php,v 1.3 2005/06/23 13:36:22 timo_h Exp $
******************************************************************************/
class pdImageContainer extends pdContainer {
// Attributes
/**
* Represent ...
*/
var $_image;
/**
* Represent ...
*/
var $_mode;
function pdImageContainer ()
{
parent::pdContainer();
$this->setImageMode("scale");
}
// Operations
/**
* Does ...
* @param mode
*/
function setImageMode($mode)
{
$this->_mode = $mode;
} // end operation setImageMode
/**
* Does ...
* @param path
*/
function setImage($path)
{
$this->_image = $path;
} // end operation setImage
function scaleImg ($x, $y, $maxX, $maxY)
{
/* Calculate the aspect ratio */
$aspectXY = $x / $y;
$aspectYX = $y / $x;
/* Check which axis has the higher aspect ratio */
if (($maxX / $x) < ($maxY / $y))
{
$targetY = $y * ($maxX / $x);
$targetX = $maxX;
} else {
$targetX = $x * ($maxY / $y);
$targetY = $maxY;
}
return array($targetX, $targetY);
}
function customRender ()
{
global $_pdfDom_PDF;
list($x, $y, $x1, $y1) = $this->getInnerRectangle();
list($imgW, $imgH) = getimagesize($this->_image);
$w = $x1 - $x;
$h = $y1 - $y;
list($w, $h) = $this->scaleImg($imgW, $imgH, $w, $h);
switch ($this->_mode)
{
case "scale":
$_pdfDom_PDF->Image($this->_image, $x, $y, $w, $h);
break;
case "stretch":
$_pdfDom_PDF->Image($this->_image, $x, $y, $x1 - $x, $y1 - $y);
break;
default:
list($w, $h) = $this->correctAspectRatio($w, $h, $w, $h);
break;
}
}
function preRender ()
{
if ($this->_mode == "scale")
{
list($x, $y, $x1, $y1) = $this->getInnerRectangle();
list($imgW, $imgH) = getimagesize($this->_image);
$w = $x1 - $x;
$h = $y1 - $y;
list($w, $h) = $this->scaleImg($imgW, $imgH, $w, $h);
$this->coordinates->setWidth($w);
$this->coordinates->setHeight($h);
}
}
} // end class pdImageContainer
?>