[Typo3-dev] use IM combine funtion in an extension
Zach Davis
zach at castironcoding.com
Tue Feb 22 15:36:34 CET 2005
I recently made a gallery extension, and I spent a lot of time trying to
use gifbuilder to create a watermark. In the end, I decided not to do it
with gifbuilder -- first, it didn't make sense to create gifs (256
colors max) for photos in an image gallery. Second, it was slow and
difficult to work with.
In the end, we decided to modify a function we found at
http://www.phpgeek.com/articles.php?content_id=6 and add some caching
(which, as far as we were concerned, was the big plus of using gifbuilder).
I'll include the function we used, for what it's worth, below. This
approach also allowed the gallery to determine whether the watermark
should be place horizontally or vertically, depending on the size of the
image.
function watermark($srcfilename, $newname, $watermarks, $quality) {
$imageInfo = getimagesize($srcfilename);
$width = $imageInfo[0];
$height = $imageInfo[1];
// find a watermark that fits the image, first try horizontal, then
vertical
$logoinfo = getimagesize($watermarks[0]);
$logowidth = $logoinfo[0];
$logoheight = $logoinfo[1];
$watermarkKey = 0;
if($logowidth > $width) {
$logoinfo = getimagesize($watermarks[1]);
$logowidth = $logoinfo[0];
$logoheight = $logoinfo[1];
$watermarkKey = 1;
}
$horizextra =$width - $logowidth;
$vertextra =$height - $logoheight;
$horizmargin = round($horizextra / 2);
$vertmargin = round($vertextra / 2);
$photoImage = ImageCreateFromJPEG($srcfilename);
ImageAlphaBlending($photoImage, true);
$logoImage = ImageCreateFromPNG($watermarks[$watermarkKey]);
$logoW = ImageSX($logoImage);
$logoH = ImageSY($logoImage);
ImageCopy($photoImage, $logoImage, $horizmargin, $vertmargin, 0, 0,
$logoW, $logoH);
ImageJPEG($photoImage,$newname, $quality);
ImageDestroy($photoImage);
ImageDestroy($logoImage);
}
To see it in action, check out:
http://ostudio.com/index.php?id=7&no_cache=1&view=single&cat_uid=0&sub_cat_uid=3&image_uid=354
best,
Zach
Wengrzik, Andreas wrote:
> Hello!
>
> I try to use the combin function in a gallery extension... but with the image .params options i can
> only use the
>
> $this->imgconf['file.']['params'] = '-gravity SouthEast -font Tahoma -pointsize 11 -draw "fill black text 1,1 \'myText\' text 0,0 \'myText\' fill white text -1,-1 \'myText\'"';
>
>
> this looks a little big like an watermark, but i need to combine two image to get an transparent watermark - that will look much better than only text in an image.
> I also want to use an image not only text...
>
> Any suggestions how to get it work??
> Anyone done this before?
>
> Thanks a lot!!
>
> bye
>
> -andreas
More information about the TYPO3-dev
mailing list