dezkit Posted May 5, 2008 Share Posted May 5, 2008 i was googling "php watermark" and i stumbled upon this code.... but i can't get it to work... why? index.php <?php $image = $HTTP_GET_VARS['image']; // Useful if using in an img tag to call images $image = str_replace(array("/", ".."), "", $image); // Prevent abuse $overlay = 'http://www.chestysoft.com/images/watermark.png'; $dir = '../hresources/'; if ($image == NULL) { $image = 'http://www.uscg.mil/mlcpac/ischon/mwr/images/club14/club.jpg'; } if (!file_exists($dir . $image)) { die("Image does not exist."); } $w_offset = 0; $h_offset = 0; $extension = strtolower(substr($image, strrpos($image, ".") + 1)); switch ($extension) { case 'jpg': $background = imagecreatefromjpeg($dir . $image); break; case 'jpeg': $background = imagecreatefromjpeg($dir . $image); break; case 'png': $background = imagecreatefrompng($dir . $image); break; case 'gif': $background = imagecreatefromgif($dir . $image); break; default: die("Image is of unsupported type."); } $swidth = imagesx($background); $sheight = imagesy($background); imagealphablending($background, true); $overlay = imagecreatefrompng($dir . $overlay); $owidth = imagesx($overlay); $oheight = imagesy($overlay); imagecopy($background, $overlay, $swidth - $owidth - $w_offset, $sheight - $oheight - $h_offset, 0, 0, $owidth, $oheight); header("Content-type: image/jpeg"); header("Content-Disposition: filename=" . $image); imagejpeg($background); imagedestroy($background); imagedestroy($overlay); ?> i go into my index.php and it says Image doesn't exist. Link to comment https://forums.phpfreaks.com/topic/104263-php-gd/ Share on other sites More sharing options...
dezkit Posted May 5, 2008 Author Share Posted May 5, 2008 any ideas? Link to comment https://forums.phpfreaks.com/topic/104263-php-gd/#findComment-533772 Share on other sites More sharing options...
flyhoney Posted May 5, 2008 Share Posted May 5, 2008 <?php $overlay = 'http://www.chestysoft.com/images/watermark.png'; $dir = '../hresources/'; if ($image == NULL) { $image = 'http://www.uscg.mil/mlcpac/ischon/mwr/images/club14/club.jpg'; } if (!file_exists($dir . $image)) { die("Image does not exist."); } ?> If $image is null its going to try and find an image called "../hresources/http://www.uscg.mil/mlcpac/ischon/mwr/images/club14/club.jpg" Which doesnt really make sense. Make sure the image you are referencing actually exists on your server and that you are referring to it correctly. Link to comment https://forums.phpfreaks.com/topic/104263-php-gd/#findComment-533777 Share on other sites More sharing options...
dezkit Posted May 5, 2008 Author Share Posted May 5, 2008 what about this code, i don't understand, i put it in my index.php, what do i do now? <?php header('content-type: image/jpeg'); $watermark = imagecreatefrompng('watermark.png'); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $image = imagecreatetruecolor($watermark_width, $watermark_height); $image = imagecreatefromjpeg($_GET['src']); $size = getimagesize($_GET['src']); $dest_x = $size[0] - $watermark_width - 5; $dest_y = $size[1] - $watermark_height - 5; imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); ?> Link to comment https://forums.phpfreaks.com/topic/104263-php-gd/#findComment-533966 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.