Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

smarty and GD

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
gdmmzb
Smarty n00b


Joined: 14 Jan 2006
Posts: 4
Location: china

PostPosted: Sun Jan 15, 2006 2:46 am    Post subject: smarty and GD Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
ZabMilenko
Smarty n00b


Joined: 15 Jan 2006
Posts: 3

PostPosted: Sun Jan 15, 2006 2:48 am    Post subject: Reply with quote

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
View user's profile Send private message
gdmmzb
Smarty n00b


Joined: 14 Jan 2006
Posts: 4
Location: china

PostPosted: Sun Jan 15, 2006 3:05 am    Post subject: I just used your method, but the image can not be showed.why Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Jan 15, 2006 10:02 pm    Post subject: Reply with quote

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
View user's profile Send private message
gdmmzb
Smarty n00b


Joined: 14 Jan 2006
Posts: 4
Location: china

PostPosted: Mon Jan 16, 2006 12:25 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
gdmmzb
Smarty n00b


Joined: 14 Jan 2006
Posts: 4
Location: china

PostPosted: Tue Jan 17, 2006 7:42 am    Post subject: Reply with quote

My problem has been solved. Thanks in advanced!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
OpenMacNews
Smarty Rookie


Joined: 03 Aug 2004
Posts: 34
Location: Floating on Io's Methane Seas ...

PostPosted: Tue May 02, 2006 10:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
chros
Smarty Regular


Joined: 03 Mar 2006
Posts: 58

PostPosted: Wed May 03, 2006 8:35 am    Post subject: Reply with quote

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
View user's profile Send private message
Hielke Hoeve
Smarty Elite


Joined: 06 Jan 2006
Posts: 406
Location: Netherlands

PostPosted: Wed May 03, 2006 11:26 am    Post subject: Reply with quote

header -- Send a raw HTTP header Wink 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
View user's profile Send private message
OpenMacNews
Smarty Rookie


Joined: 03 Aug 2004
Posts: 34
Location: Floating on Io's Methane Seas ...

PostPosted: Wed May 03, 2006 9:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hielke Hoeve
Smarty Elite


Joined: 06 Jan 2006
Posts: 406
Location: Netherlands

PostPosted: Sat May 06, 2006 10:02 am    Post subject: Reply with quote

In general it is needed to send a header because otherwise the browser could/would interpret it as html or plaintext. Embarassed
_________________
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
View user's profile Send private message
OpenMacNews
Smarty Rookie


Joined: 03 Aug 2004
Posts: 34
Location: Floating on Io's Methane Seas ...

PostPosted: Sat May 06, 2006 5:12 pm    Post subject: Reply with quote

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. Embarassed


that's why i find it 'odd'. i thought, as well, that the header would be necessary.

Question
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP