SmokeyTheBear |
01-30-2006 10:07 PM |
heres a simple php method that might work for you.
first make adirectory called "stb" in your root. ( i.e. http://yoursite.com/stb/ )
copy and paste the following into a new text document and save it as watermark.php
( p.s. gfy screw that last lines of this part of the code up the part that says HAHAHA should be = = )
Code:
<?php
$watermark = "watermark2.png";
$image = $_SERVER["PATH_TRANSLATED"];
$size = getimagesize("$image");
$width = $size[0];
if ($width > 150)
{
$watermark = "watermark1.png";
}
if (empty($image)) die();
if (!file_exists($image)) {
header("404 Not Found");
echo "File Not Found."; die();
}
$outputType = getFileType($image);
watermark($image, $watermark, $outputType);
/**
Outputs the image $source with $watermark in the lower right corner.
@param $source the source image
@param $watermark the watermark to apply
@param $outputType the type to output as (png, jpg, gif, etc.)
defaults to the image type of $source if left blank
*/
function watermark($source, $watermark, $outputType="") {
$sourceType = getFileType($source);
$watermarkType = getFileType($watermark);
if (empty($outputType)) $outputType = $sourceType;
header("Content-type:image/$outputType");
// Derive function names
$createSource = "ImageCreateFrom".strtoupper($sourceType);
$showImage = "Image".strtoupper($outputType);
$createWatermark = "ImageCreateFrom".strtoupper($watermarkType);
// Load original and watermark to memory
$output = $createSource($source);
$logo = $createWatermark($watermark);
ImageAlphaBlending($output, true);
// Find proper coordinates so watermark will be in the lower right corner
$x = ImageSX($output) - ImageSX($logo);
$y = ImageSY($output) - ImageSY($logo);
// Display
ImageCopy($output, $logo, $x, $y, 0, 0, ImageSX($logo), ImageSY($logo));
$showImage($output);
// Purge
ImageDestroy($output);
ImageDestroy($logo);
}
function getFileType($string) {
$type = strtolower(eregi_replace("^(.*)\.","",$string));
if ($type hahahaha "jpg") $type = "jpeg";
return $type;
}
?>
Then make 2 watermark images, one for big pics and another for thumbs..
name them watermark1.png and watermark2.png put them int he same directory
then just copy and paste the following into a new text document and name it .htaccess and uplaod it into each directory you want the images to be watermarked in
Code:
AddHandler watermarked .jpg
AddHandler watermarked .jpeg
AddHandler watermarked .gif
AddHandler watermarked .png
Action watermarked http://yoursite.com/stb/watermark.php
|