Jump to content

image showing as text


brem13

Recommended Posts

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??

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.