<?php
/* PIMG module: merges two pimg images with a define xy offset */
class pimg_merge
{
/* Resources */
private $pimg;
// PIMG constructor
function __construct($pimg)
{
$this -> pimg = $pimg;
}
/*
Merges the given pimg image over the original pimg image with the given xy offset
@param: $copy - the pimg image to merge on top
@param: $x - x offset (signed)
@param: $y - y offset (signed)
@result: a pointer to the caller pimg class for furthur usage
*/
function init($copy, $x = 0, $y = 0, $pct = 100)
{
/* INPUT VALIDATORS */
if (!$copy instanceOf pimg_image)
$this -> pimg -> setDebug('The passed merge image is not a valid pimg_image resource', 'error', __CLASS__);
// Check if the $copy is actually the original pimg
if ($this -> pimg == $copy)
$copyImg = $this -> pimg -> newImage($copy -> renderString());
else
$copyImg = $copy -> handle();
// Layer over the image
if ($pct == 100)
imagecopyresampled($this -> pimg -> handle(), $copyImg, $x, $y, 0, 0, $copy -> width(), $copy -> height(), $copy -> width(), $copy -> height());
elseif ($pct)
imagecopymerge($this -> pimg -> handle(), $copyImg, $x, $y, 0, 0, imagesx($copyImg), imagesy($copyImg), $pct);
// Return the caller pimg instance
return $this -> pimg;
}
}
?>
|