brem13 Posted August 1, 2010 Share Posted August 1, 2010 hey, i'm trying to add a watermark to pictures that show up, however it is only showing as text here is the code $watermark = imagecreatefrompng('watermark1.png'); $image = imagecreatefromjpeg("/userImages/big/".$pic); imagecopymerge($image, $watermark, 5, 5, 0, 0, 135, 35, 100); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); also, where i fould how to do this, said u have to put a header('content-type: image/jpeg'); code at the top of the page or else it would read as text, however, when i do that, the whole page disappears except for a question mark thing indicating a picture should be there? what do i do?? Quote Link to comment https://forums.phpfreaks.com/topic/209478-image-showing-as-text/ Share on other sites More sharing options...
jcbones Posted August 1, 2010 Share Posted August 1, 2010 You have to have the header() function in there for it to work. You are merging the $watermark into the $image, but if $image isn't returning an image, then it will fail. Are you sure that $pic is set, and is a valid image in that directory? Quote Link to comment https://forums.phpfreaks.com/topic/209478-image-showing-as-text/#findComment-1093754 Share on other sites More sharing options...
brem13 Posted August 1, 2010 Author Share Posted August 1, 2010 yes, the pic is there, i tested the same code in a blank page with the header and it worked, but when i add the code to the section of a page i want it in, and add the header to the top, it only shows a 'little box with a question mark(im on a mac) indicating a picture should be there' - the image address for that is just the url to that page and shows nothing else on the page Quote Link to comment https://forums.phpfreaks.com/topic/209478-image-showing-as-text/#findComment-1093757 Share on other sites More sharing options...
jcbones Posted August 1, 2010 Share Posted August 1, 2010 i tested the same code in a blank page with the header and it worked, but when i add the code to the section of a page i want it in, and add the header to the top, That is why it isn't working. You must have all of your code in a separate file. If $pic is defined in your main file, then pass it as a get parameter. main.php <?php $pic = 'somepic.jpg'; ?> <img src="pic.php?pic=<?php echo $pic; ?>" alt="<?php echo $pic; ?>"/> pic.php header('content-type: image/jpeg'); $pic = $_GET['pic']; $watermark = imagecreatefrompng('watermark1.png'); $image = imagecreatefromjpeg("/userImages/big/".$pic); imagecopymerge($image, $watermark, 5, 5, 0, 0, 135, 35, 100); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); Quote Link to comment https://forums.phpfreaks.com/topic/209478-image-showing-as-text/#findComment-1093758 Share on other sites More sharing options...
brem13 Posted August 1, 2010 Author Share Posted August 1, 2010 it worked, thanks man!!! Quote Link to comment https://forums.phpfreaks.com/topic/209478-image-showing-as-text/#findComment-1093767 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.