tallberg Posted January 22, 2007 Share Posted January 22, 2007 Hi Im attempting to out put images with a water mark on the fly. I have a script that works fine. below.The problem im experiancing has somthing to do with the header. Im unable to have any thing on the page other than the image with its water mark?[quote]<?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('image.jpg'); $size = getimagesize('image.jpg'); $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); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title><? print($header) ?></title><link href="stylesheet.css" rel="stylesheet" type="text/css" /><meta name="description" content="" /><meta name="keywords" content="" /><script type="text/JavaScript" src="javascript.js"></script></head><body><p>text ... text ..text ... text ..text ... text ..</p></body></html>[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/35204-generating-water-marks-on-the-fly/ Share on other sites More sharing options...
Cep Posted January 22, 2007 Share Posted January 22, 2007 Just a question really but why put the output of the $header variable in the title tags? Quote Link to comment https://forums.phpfreaks.com/topic/35204-generating-water-marks-on-the-fly/#findComment-166228 Share on other sites More sharing options...
tallberg Posted January 22, 2007 Author Share Posted January 22, 2007 Didnt think about that. However the following out puts the image but no text below[quote]<?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('image.jpg'); $size = getimagesize('image.jpg'); $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); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title></title><link href="stylesheet.css" rel="stylesheet" type="text/css" /><meta name="description" content="" /><meta name="keywords" content="" /></head><body><p>text ... text ..text ... text ..text ... text ..</p><? print($header) ?></body></html>[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/35204-generating-water-marks-on-the-fly/#findComment-166240 Share on other sites More sharing options...
Cep Posted January 22, 2007 Share Posted January 22, 2007 I think the problem here is your not following the flow of your document.Your program flow is doing exactly what your telling it by placing the the text and then the image.What I think you want to try and do is utilise CSS and set a class on your <P> tag, or in fact the whole body tag to set your image as the background image.If your aiming to have the watermark appear over your text you will need to use floats in CSS. Quote Link to comment https://forums.phpfreaks.com/topic/35204-generating-water-marks-on-the-fly/#findComment-166242 Share on other sites More sharing options...
tallberg Posted January 22, 2007 Author Share Posted January 22, 2007 That is not the issue. I will be using this script to water mark photograpic images on the fly.Those images will not be the first thing on the page. they will be in the body of the document.Thanks for replying Quote Link to comment https://forums.phpfreaks.com/topic/35204-generating-water-marks-on-the-fly/#findComment-166249 Share on other sites More sharing options...
tallberg Posted January 22, 2007 Author Share Posted January 22, 2007 to explain further. The text does not appear at all. Only the image. My problem is related to simple not understanding header stuff. Quote Link to comment https://forums.phpfreaks.com/topic/35204-generating-water-marks-on-the-fly/#findComment-166309 Share on other sites More sharing options...
Cep Posted January 22, 2007 Share Posted January 22, 2007 Ah I see, Well from what I can glean from your script you are calling an image with the header function, watermarking it, destroying the image, destroying the watermark and then calling back header.Try this,[code=php:0]<?phpheader('content-type: image/jpeg'); $watermark = imagecreatefrompng('watermark.png'); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $image = imagecreatetruecolor($watermark_width, $watermark_height); $image = imagecreatefromjpeg('image.jpg'); $size = getimagesize('image.jpg'); $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($watermark);?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title></title><link href="stylesheet.css" rel="stylesheet" type="text/css" /><meta name="description" content="" /><meta name="keywords" content="" /></head><body><p>text ... text ..text ... text ..text ... text ..</p><? echo "<img src='{$image}' alt='' />"; ?></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35204-generating-water-marks-on-the-fly/#findComment-166326 Share on other sites More sharing options...
redbullmarky Posted January 22, 2007 Share Posted January 22, 2007 as far as i know, the original and suggested methods are not going to work due to the different headers required to send both an image and a picture. you cant send two content headers from the same script (the other being the default - text/html)move all your PHP from before your DOCTYPE into a new file, called (for example) image.php. then where you want the image, you need:[code]<img src="/image.php" alt="" />[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35204-generating-water-marks-on-the-fly/#findComment-166327 Share on other sites More sharing options...
tallberg Posted January 22, 2007 Author Share Posted January 22, 2007 Thank you very very much Quote Link to comment https://forums.phpfreaks.com/topic/35204-generating-water-marks-on-the-fly/#findComment-166491 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.