English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

The code below watermarks an image with php. To so this the header needs to be set to: header('content-type: image/png');
But after the script has done its stuff with the image i then want it to header me to another page but it cant as the header is already sent, what can i do to get around this? or is it impossible?
header('content-type: image/png');
$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = imagecreatefrompng($_GET['src']);
$size = getimagesize($_GET['src']);
$dest_x = $size[0] - $watermark_width - 2;
$dest_y = $size[1] - $watermark_height - 25;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 50, 0, $watermark_width, $watermark_height, 100);
imagepng($image);
imagepng($image, 'lightwaves.png');
?>

2007-10-27 06:52:59 · 3 answers · asked by peter s 1 in Computers & Internet Programming & Design

3 answers

No you can't do what you are trying to do. What you are doing is using php to generate and return an image. This makes sense any place that a normal image would make sense, for example as the src of an image tag ie img src="yourscript.php"

I'm not sure what you are trying to accomplish, but an image has no context within html by itself. If what you want to do is display the image, then forward to another page some time later then you can use a 2nd page where you call the image script in an img tag as I illustrated above, then use a meta refresh html header to go to the other page a few seconds later.

If that doesn't match your problem, I think you need to rethink the logic of what you're trying to do, as showing an image and immediately moving to another page before the original image can even be seen, doesn't make much sense.

2007-10-27 07:34:33 · answer #1 · answered by Gizmo L 4 · 0 0

This is a classical problem...
For the headers to be active (able to be sent), you must NOT output ANYTHING to the client, NOT EVEN A SPACE!
A space line at the top of a page, and your headers go.
You can't show the proper stuff here: YA can't cope with these.
I have had that problem before and solved it.
Zip ALL the php files involved as they are: a space line makes a difference!) and send them to me directly (not through YA)
Make sure you put in your message your nickname and a copy of your question. (So I know who you are: my spam is hard!).
jrc@skytargets.com.
If I can mod your code, I'll do it and send it back to you.
Otherwise, I'll give you guidance.
JR

2007-10-27 14:14:52 · answer #2 · answered by just "JR" 7 · 0 0

Your problem could be caused by a space or HTML code before the .

2007-10-27 14:03:22 · answer #3 · answered by g33kish 3 · 0 0

fedest.com, questions and answers