View Single Post
Old 01-25-2006, 07:47 PM  
SmokeyTheBear
►SouthOfHeaven
 
SmokeyTheBear's Avatar
 
Join Date: Jun 2004
Location: PlanetEarth MyBoardRank: GerbilMaster My-Penis-Size: extralarge MyWeapon: Computer
Posts: 28,609
save the following as .htaccess
this is what the htaccess should look like ( put it in the directory with the pics

Code:
AddHandler watermarked .jpg
AddHandler watermarked .jpeg
AddHandler watermarked .gif
AddHandler watermarked .png

Action watermarked http://www.yoursite.com/watermarkscript.php
then the watermarkscript.php should look like this , it can reside anywhere , just point the htaccess to this file..

make a watermark.png and place it int he same directory as the watermarkscript.php

Code:
<?php
$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.
   @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;
}
( hahaha should read == )
__________________
hatisblack at yahoo.com
SmokeyTheBear is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote