View previous topic :: View next topic |
Author |
Message |
gdmmzb Smarty n00b
Joined: 14 Jan 2006 Posts: 4 Location: china
|
Posted: Sun Jan 15, 2006 2:46 am Post subject: smarty and GD |
|
|
Hi, I have some class of the image using PHP GD functions.
Now I want to add it in my html page with the smarty template.
I try to include the php files of the class in the tpl files, but when
I browsed the page, the page showed the warning information
as for:
Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\exp5.php:2) in C:\Program Files\Apache Group\Apache2\htdocs\smarty\libs\3dpie-old.php on line 153
The line 153 is "header("Content-type: image/gif");".
I don't know the reason.Can someone tell me about this?Thank you! |
|
Back to top |
|
ZabMilenko Smarty n00b
Joined: 15 Jan 2006 Posts: 3
|
Posted: Sun Jan 15, 2006 2:48 am Post subject: |
|
|
You don't want to include them, you want to use an image tag:
<img src="my_php_gd_image.php">
and make sure there are no leading or trailing chars outside of the php tags. One of the biggest issues for GD images is people press the enter key after the closing ?> |
|
Back to top |
|
gdmmzb Smarty n00b
Joined: 14 Jan 2006 Posts: 4 Location: china
|
Posted: Sun Jan 15, 2006 3:05 am Post subject: I just used your method, but the image can not be showed.why |
|
|
I just used your method, but the image can not be showed.why?
And my php file run normally and show the image of pie.
Can you give me an example? I'm poor of this! |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun Jan 15, 2006 10:02 pm Post subject: |
|
|
I think that what ZabMilenko is saying is that you have to put the GD image creation into a separate file altogether. That's because the browser starts an new request for the linked images. It seems you are trying to send the image inline with the actual html document. |
|
Back to top |
|
gdmmzb Smarty n00b
Joined: 14 Jan 2006 Posts: 4 Location: china
|
Posted: Mon Jan 16, 2006 12:25 am Post subject: |
|
|
Do you mean I want to put the image that created by the php file into
a new html page?
But how can I put it into smarty tpl file?
for example, this is a simple tpl file:
<html>
<head><title>php image in tpl</title></head>
<body>
The image's name is {$name}
<img src="3dpie.php">
</body>
</html> |
|
Back to top |
|
gdmmzb Smarty n00b
Joined: 14 Jan 2006 Posts: 4 Location: china
|
Posted: Tue Jan 17, 2006 7:42 am Post subject: |
|
|
My problem has been solved. Thanks in advanced! |
|
Back to top |
|
OpenMacNews Smarty Rookie
Joined: 03 Aug 2004 Posts: 34 Location: Floating on Io's Methane Seas ...
|
Posted: Tue May 02, 2006 10:48 pm Post subject: |
|
|
gdmmzb wrote: | My problem has been solved. Thanks in advanced! |
hi,
i'm attempting the same, and having the same issues ...
could you share an exmaple of how you finally solved this?
also, are you physically saving the image to disk, then displaying it, or passing it inline with, e.g., fpassthru() in the image-generating script.
thanks! |
|
Back to top |
|
chros Smarty Regular
Joined: 03 Mar 2006 Posts: 58
|
Posted: Wed May 03, 2006 8:35 am Post subject: |
|
|
gdmmzb wrote: |
for example, this is a simple tpl file:
<html>
<head><title>php image in tpl</title></head>
<body>
The image's name is {$name}
<img src="3dpie.php">
</body>
</html> |
This should be working, if 3dpie.php file is good (and you can try this by directly accessing it in the browser.) |
|
Back to top |
|
Hielke Hoeve Smarty Elite
Joined: 06 Jan 2006 Posts: 406 Location: Netherlands
|
Posted: Wed May 03, 2006 11:26 am Post subject: |
|
|
header -- Send a raw HTTP header You can't send it twice...
Simply have page1.php be the page that builds a smarty template and sends it to the browser, then where you want to display an image use Code: | <img src="image1.php" /> |
Then have image1.php create and image and not a smarty page. Just something like:
Code: | <?
header("Content-type: image/png");
$img = createpng(...);
echo $img;
?> |
You can add some checks in image1.php to make sure that the request is legit but doing things with Smarty in image1.php is futile as you won't be displaying a html page but just sending the raw image data to the browser. This data will be placed in the <img /> tag just as it would when the browser requests a static image (.jpg or .png). _________________ Debug XHTML Compliance
SmartyPaginate
Smarty License Questions
---
(About Unix) The learning curve is full of aha! moments, such as that glorious day that the full beauty of grep and, later, find is revealed in all its majesty. --- Robert Uhl <ruhl@4dv.net> |
|
Back to top |
|
OpenMacNews Smarty Rookie
Joined: 03 Aug 2004 Posts: 34 Location: Floating on Io's Methane Seas ...
|
Posted: Wed May 03, 2006 9:58 pm Post subject: |
|
|
hi all.
thx for the pointers.
turns out that:
*.tpl:
<img src='something.php?pass_this=<ste: $other_var :ste>'>
with,
something.php:
imagepng($myImage);
does the trick. fwiw, adding the header info causes the image to simply NOT appear ... with NO error fired.
odd.
ccheers,
richard |
|
Back to top |
|
Hielke Hoeve Smarty Elite
Joined: 06 Jan 2006 Posts: 406 Location: Netherlands
|
Posted: Sat May 06, 2006 10:02 am Post subject: |
|
|
In general it is needed to send a header because otherwise the browser could/would interpret it as html or plaintext. _________________ Debug XHTML Compliance
SmartyPaginate
Smarty License Questions
---
(About Unix) The learning curve is full of aha! moments, such as that glorious day that the full beauty of grep and, later, find is revealed in all its majesty. --- Robert Uhl <ruhl@4dv.net> |
|
Back to top |
|
OpenMacNews Smarty Rookie
Joined: 03 Aug 2004 Posts: 34 Location: Floating on Io's Methane Seas ...
|
Posted: Sat May 06, 2006 5:12 pm Post subject: |
|
|
hi hielke,
Hielke Hoeve wrote: | In general it is needed to send a header because otherwise the browser could/would interpret it as html or plaintext. |
that's why i find it 'odd'. i thought, as well, that the header would be necessary.
|
|
Back to top |
|
|