jarvis Posted February 5, 2010 Share Posted February 5, 2010 Hi All, Hope someone can help. The below code displays a watermark over an image, how can I alter the code so it actually writes it on the image? Otherwise, you can download the pic and the watermark isn't on it.: $imagesource = $_GET['path']; $filetype = substr($imagesource,strlen($imagesource)-4,4); $filetype = strtolower($filetype); if($filetype == ".gif") $image = @imagecreatefromgif($imagesource); if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource); if($filetype == ".png") $image = @imagecreatefrompng($imagesource); if (!$image) die(); $watermark = @imagecreatefromgif('watermark.gif'); $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); Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/191049-embed-watermark-onto-an-image/ Share on other sites More sharing options...
jarvis Posted February 5, 2010 Author Share Posted February 5, 2010 Hi, is this along the right lines: $SourceFile = $_GET['path']; function watermarkImage ($SourceFile, $DestinationFile) { list($width, $height) = getimagesize($SourceFile); $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($SourceFile); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height); $src = imagecreatefromgif('watermark.gif'); imagecopymerge($image_p, $src, 0, 0, 0, 0, 800, 600, 75); echo $SourceFile; if ($DestinationFile<>'') { imagejpeg ($image_p, $DestinationFile, 100); } else { header('Content-Type: image/gif'); imagejpeg($image_p, null, 100); }; imagedestroy($image); imagedestroy($image_p); }; Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/191049-embed-watermark-onto-an-image/#findComment-1007424 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.