daveh33 Posted November 11, 2008 Share Posted November 11, 2008 Hi - I am trying to get a script to work which can watermark my images - I am working of this tutorial: - http://www.trap17.com/index.php/watermark-image-simple-php-script_t36015.html I have a file called watermark.php with the below code: - <?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); ?> Within the directory I have - watermark.php, index.php, watermark.gif & test.jpg index.php simply contains: - <? header("Content-type: image/jpeg"); ?> <img src="watermark.php?path=test.jpg&watermark=watermark.gif" /> All it seems to display is the page url ... no image - any ideas why?? Link to comment https://forums.phpfreaks.com/topic/132286-simple-php-watermark-script/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.