Hi guys. Total newb to PHP... but I have PHP Nuke and now I like it. Anyway, I looked at my web statistics today and found out I have like 20 people using my bandwidth to show my pictures on their sites, especially in forums and crap. Well, it really doesn't bother me THAT much because my host gives me like 20 gigs of bandwidth and my site is pretty low key... I don't even think I achieve 1gb per month, but anyway... so I figure they can hotlink all the want but my way to get more hits to my site while they do it is to do the watermark.
Anyone firmiliar with cardomain probably knows what I'm really wanting here, when you view the image on cardomain's site it's all fine and dandy, but then you hotlink and it shows their logo in the bottom corner.
Well, now that I've totally shown my newbness, I found a site that said to basically do the same thing you use an .htaccess file on your image folder...
AddHandler watermarked .jpg
AddHandler watermarked .jpeg
AddHandler watermarked .gif
AddHandler watermarked .pngAction watermarked /images/watermarker.php
So fine and dandy, then the watermarker.php file...
<?php
phpinfo(); die();
$watermark = "watermark.png";
$image = $_SERVER["PATH_TRANSLATED"];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.
@ $source the source image
@ $watermark the watermark to apply
@ $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 == "jpg") $type = "jpeg";
return $type;
}
Well, for one I tried it and this is what happens to the images...
The main thing with the above script though, is that from what I see it doesn't recognize whether or not the image is being accessed by my domain or someone else's site.. I've tried finding more information and found something that said to use $_server[HTTP_REFERER] but I don't know how to. Could someone please point me in the right direction here?
I did a search on the forum, because I figured this was a pretty popular question and although I did find a lot of watermark threads, most said "using GD" and what not, and I'm not using GD. Anyway, any help is greatly appreciated, sorry for the newb-ness.