Hi there
I have a custom image decorator for creating watermarks and would like to set the filename dynamically in php for each image? How would I do this?
These are the functions in my image decorator:
public function CroppedCopyrightImage($width, $height)
{
if ($this->owner->ID && $this->owner->Filename && Director::fileExists($this->owner->Filename))
{
$cacheFile = $this->owner->cacheFilename("CroppedCopyrightImage", $width, $height);
if (!file_exists("../".$cacheFile) || isset ($_GET['flush']))
{
$this->generateCroppedCopyrightImage($width, $height);
}
return new Image_Cached($cacheFile);
}
}
public function generateCroppedCopyrightImage($width, $height)
{
$cacheFile = $this->owner->cacheFilename("CroppedCopyrightImage", $width, $height);
$gd = new CustomGD("../".$this->owner->Filename);
if ($gd->hasGD())
{
$gd = $gd->croppedResize($width,$height)->CopyrightImage($this->owner->CopyrightText);
if ($gd)
{
$gd->writeTo("../".$cacheFile);
}
}
}
And this is the function in my extended GD class for creating the watermark:
class CustomGD extends GD
{
public function watermarkImage(){
$watermark = imagecreatefrompng(Director::absoluteBaseURL().'mysite/images/watermark_2.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
imagealphablending($watermark, false);
imagesavealpha($watermark, true);
$dest_x = 0;
$dest_y = 0;
if ($this->gd){
imagecopymerge($this->gd, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 15);
$output = new GD();
$output->setGD($this->gd);
return $output;
}
}
public function CopyrightImage($text = ''){
$font = $_SERVER['DOCUMENT_ROOT'] . '/ItalienskVinguideUpgrade2_4_5/mysite/code/arial.ttf';
if ($this->gd){
$im = $this->gd;
$width = imagesx($im);
$height = imagesy($im);
$fontSize = 8;
$angle = 0;
imageSaveAlpha($im, true);
ImageAlphaBlending($im, true);
$black = imagecolorallocatealpha($im, 153, 19, 31, 0);
imageSaveAlpha($im, true);
ImageAlphaBlending($im, true);
$dimensions = imagettfbbox($fontSize, $angle, $font, $text);
$textWidth = abs($dimensions[4] - $dimensions[0]);
imagettftext($this->gd, $fontSize, $angle, ($width - $textWidth - 10), 15, $black, $font, $text);
$output = new GD();
$output->setGD($this->gd);
return $output;
}
}
}
I hope someone can help me?