alexsmith2709 Posted July 18, 2011 Share Posted July 18, 2011 Hi, I have some code to put a text watermark on an image (using imagettftext). The code i have works in a php file on its own but when i add it to my existing page i get problems. Firstly i had a problem with the "headers already sent..." problem but that was because i had header('Content-type: image/jpg'); with the rest of my code. Now i have moved "header('Content-type: image/jpg');" to the beginning of my html file and the rest of the PHP code where i want the image on my page. Now i dont get any image displayed. The code im using is: <?php //load image $im = imagecreatefromjpeg('C11ABX.jpg'); //figure out where to put the text $imagesize = getimagesize('C11ABX.jpg'); $x_offset = 50; $y_offset = $imagesize[1] - 20; //text color $textcolor = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); //set font $font = 'detaranto.ttf'; //set size $size = '20'; //set angle $angle = '45'; //set text $text = 'SAMPLE'; imagettftext ($im ,$size ,$angle ,$x_offset ,$y_offset ,$textcolor ,$font ,$text ); //output watermarked image imagejpeg($im); ?> Any help would be great. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/242256-image-watermark-text-problem/ Share on other sites More sharing options...
Alex Posted July 18, 2011 Share Posted July 18, 2011 The code i have works in a php file on its own but when i add it to my existing page i get problems. That's how it works. You have it in a separate file, and then you use that php file as you would any other image resource: <img src="thatphpfile.php" alt="..." /> Quote Link to comment https://forums.phpfreaks.com/topic/242256-image-watermark-text-problem/#findComment-1244149 Share on other sites More sharing options...
dzelenika Posted July 18, 2011 Share Posted July 18, 2011 I think there's an error happening on server. Open error log to see which error. Quote Link to comment https://forums.phpfreaks.com/topic/242256-image-watermark-text-problem/#findComment-1244150 Share on other sites More sharing options...
alexsmith2709 Posted July 18, 2011 Author Share Posted July 18, 2011 Oh ok, thanks very much. That works. Eventually I would like to watermark each image in a certain folder (the photos im putting on the site) so i dont really want lots of PHP files if neccessary. Also to do that i'd like to know how to use this code (or something similar) to use this code to put a watermark on each image instead of just stating each filename. Im guessing i would need something like <img src="image.php?imagename"> or something like that once i have the code to get all images. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/242256-image-watermark-text-problem/#findComment-1244151 Share on other sites More sharing options...
Alex Posted July 18, 2011 Share Posted July 18, 2011 Yeah, pretty much. Something like: url: image.php?file=someimage.jpg Then use $_GET['file'] to know what file to load. Don't forget to sanitize that input. Quote Link to comment https://forums.phpfreaks.com/topic/242256-image-watermark-text-problem/#findComment-1244220 Share on other sites More sharing options...
alexsmith2709 Posted July 18, 2011 Author Share Posted July 18, 2011 Thanks, However after not playing with PHP for a while im having a complete mental block. How do i get the image names? Sorry, just cant seem to think of what to do! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/242256-image-watermark-text-problem/#findComment-1244260 Share on other sites More sharing options...
alexsmith2709 Posted July 18, 2011 Author Share Posted July 18, 2011 I've figured it out now. Thanks for all the help Quote Link to comment https://forums.phpfreaks.com/topic/242256-image-watermark-text-problem/#findComment-1244268 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.