31 Mar 2010, 12:24 AM
New Zenner
- Join Date:
- Jan 2008
- Posts:
- 74
- Plugin Contributions:
- 0
Watermark Images simpler NOT Image Handler 2
Has anyone ever added a watermark to images that is not Image Handler? I don't like that IM2 renames the images and interferes with other mods, but I really like the watermark. It just seems like too much script for what I really want. I found this script that looks like it would work great, but for the life of me I can't find where one would add the code to call it.
<?php
// this script creates a watermarked image from an image file - can be a .jpg .gif or .png file
// where watermark.gif is a mostly transparent gif image with the watermark - goes in the same directory as this script
// where this script is named watermark.php
// call this script with an image tag
// <img src="watermark.php?path=imagepath"> where path is a relative path such as subdirectory/image.jpg
$imagesource = $_GET['path'];
$watermarkPath = $_GET['watermark'];
$filetype = substr($imagesource,strlen($imagesource)-4,4);
$filetype = strtolower($filetype);
$watermarkType = substr($watermarkPath,strlen($watermarkPath)-4,4);
$watermarkType = strtolower($watermarkType);
if($filetype == ".gif")
$image = @imagecreatefromgif($imagesource);
else
if($filetype == ".jpg" || $filetype == "jpeg")
$image = @imagecreatefromjpeg($imagesource);
else
if($filetype == ".png")
$image = @imagecreatefrompng($imagesource);
else
die();
if(!$image)
die();
if($watermarkType == ".gif")
$watermark = @imagecreatefromgif($watermarkPath);
else
if($watermarkType == ".png")
$watermark = @imagecreatefrompng($watermarkPath);
else
die();
if(!$watermark)
die();
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
$watermarkwidth = imagesx($watermark);
$watermarkheight = imagesy($watermark);
$startwidth = (($imagewidth - $watermarkwidth)/2);
$startheight = (($imageheight - $watermarkheight)/2);
imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
?>
you would call it with something like this
<img src="watermark.php?path=imagePath.ext&watermark=watermarkPath.gif>
or
<img src="watermark.php?path=imagePath.ext&watermark=watermarkPath.png>
I'm using slimbox, so it may not be possible or rather it may not be easy.