Re: [PHP] how to display GD graphic in web page

2005-10-25 Thread Chris
Thanks for the detailed explanation.

I should have expanded further on my design goals though. I initiated my 
examination of this problem when I tried to generate my "on-the-fly" images 
with a class method like:

// on_the_fly.php

class on_the_fly {
function on_the_fly() {
}
function a_graphic() {
 $image = imagecreatefrompng("my_graphic.png");
 imagepng($image);
 }
}


then call the method as needed as in:

// my_page.php


Untitled Document



include ('on_the_fly.php');
$otf_graphic = new on_the_fly();
echo "a_graphic()">;




This resulted in a page filled with random characters.

So I interpret from your response that I'm still unable to reference "a_graphic()"> and MUST create my on-the-fly graphic in a 
*.php file or *.png as you suggest.

Thanks
Chris

""Richard Lynch"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Mon, October 24, 2005 7:14 pm, Chris wrote:
>> I don't understand what is going on with a simple example I created to
>> understand how GD graphics are presented in a web page.
>
> Basically, you were right the first time.
>
> Think of it this way:
>
> HTML pages generally have, well, HTML in them.
>
> Sometimes that HTML has an IMG tag, and that provides a URL to an image.
>
> But, with static images, you don't copy/paste the image itself right
> into your HTML.
>
> It's just another URL that the browser gets after it gets the HTML.
>
> PHP doesn't change any of this, really, except that now the URL for
> the image just *happens* to be an image that is composed on the fly.
>
>> Now if I treat graphic.php as an image, and reference in another page
>
> graphic.php *is* an image, just like, any other image.
>
> So you should treat it like an image.
>
>> my_graphic.png is no longer displayed and the web page gets filled
>> with
>> random characters.
>
> If you had a PNG, and if you opened up that file in Notepad/BBEdit/vi
> and you copied all the stuff out of it and pasted it into your HTML,
> that's pretty much what you would get, right?
>
> Just like you just did with PHP doing the "paste"
>
> Now, one little caveat:
>
> Microsoft, in its infinite wisdom, frequently IGNORES the
> "Content-type:" head from the HTTP specification in various versions
> of Internet Explorer.
>
> Instead, MS IE will examine the URL and see: graphic.php and say, "Oh,
> never mind that silly HTTP specification and Content-type, *this* must
> be a .php file because it ends in .php, and everybody uses 8.3,
> right?"
>
> Then, of course, MS IE says, "Oh my goodness! I don't know how to
> handle a '.php' file! Woe is me!" and then pops up a Window telling
> the user it has encountered a file of type .php and doesn't know what
> to do with it.
> [I'll tell 'em what to do with it... :-)]
>
> Anyway, if you're going to do much with dynamic images, you might as
> well start getting them to have ".png" filenames now.
>
> There are lots of techniques for this, but the whole ignoring
> Content-type mess of MS IE, and because of their similar idiocy with
> GET parameters for .pdf and .swf files, I recommend this:
>
> Make your HTML and your URL indistinguishable from static HTML/URL, so
> that MS IE can't *possibly* [bleep] up.
>
> Put this in an .htaccess file next to the graphic.php script:
>
> 
>  ForceType application/x-httpd-php
> 
>
> Now, rename graphic.php to graphic.png
>
> Voila.
>
> MS IE "sees" graphic.png and "knows" it's a PNG.
>
> Apache was told that graphic.png is *really* a PHP script, so Apache
> fires up PHP and PHP/GD make the image and spit it out.
>
> Your HTML and PNG are indistinguishable by the browser from a static
> image, and they'd have to break every PNG out there to make yours not
> work.  Which, knowing MS, is not *impossible* but it's a lot less
> likely than their various versions of IE that will break on
> http://example.com/graphic.php as a PNG image URL.
>
> -- 
> Like Music?
> http://l-i-e.com/artists.htm 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] how to display GD graphic in web page

2005-10-24 Thread Richard Lynch
On Mon, October 24, 2005 7:14 pm, Chris wrote:
> I don't understand what is going on with a simple example I created to
> understand how GD graphics are presented in a web page.

Basically, you were right the first time.

Think of it this way:

HTML pages generally have, well, HTML in them.

Sometimes that HTML has an IMG tag, and that provides a URL to an image.

But, with static images, you don't copy/paste the image itself right
into your HTML.

It's just another URL that the browser gets after it gets the HTML.

PHP doesn't change any of this, really, except that now the URL for
the image just *happens* to be an image that is composed on the fly.

> Now if I treat graphic.php as an image, and reference in another page

graphic.php *is* an image, just like, any other image.

So you should treat it like an image.

> my_graphic.png is no longer displayed and the web page gets filled
> with
> random characters.

If you had a PNG, and if you opened up that file in Notepad/BBEdit/vi
and you copied all the stuff out of it and pasted it into your HTML,
that's pretty much what you would get, right?

Just like you just did with PHP doing the "paste"

Now, one little caveat:

Microsoft, in its infinite wisdom, frequently IGNORES the
"Content-type:" head from the HTTP specification in various versions
of Internet Explorer.

Instead, MS IE will examine the URL and see: graphic.php and say, "Oh,
never mind that silly HTTP specification and Content-type, *this* must
be a .php file because it ends in .php, and everybody uses 8.3,
right?"

Then, of course, MS IE says, "Oh my goodness! I don't know how to
handle a '.php' file! Woe is me!" and then pops up a Window telling
the user it has encountered a file of type .php and doesn't know what
to do with it.
[I'll tell 'em what to do with it... :-)]

Anyway, if you're going to do much with dynamic images, you might as
well start getting them to have ".png" filenames now.

There are lots of techniques for this, but the whole ignoring
Content-type mess of MS IE, and because of their similar idiocy with
GET parameters for .pdf and .swf files, I recommend this:

Make your HTML and your URL indistinguishable from static HTML/URL, so
that MS IE can't *possibly* [bleep] up.

Put this in an .htaccess file next to the graphic.php script:


  ForceType application/x-httpd-php


Now, rename graphic.php to graphic.png

Voila.

MS IE "sees" graphic.png and "knows" it's a PNG.

Apache was told that graphic.png is *really* a PHP script, so Apache
fires up PHP and PHP/GD make the image and spit it out.

Your HTML and PNG are indistinguishable by the browser from a static
image, and they'd have to break every PNG out there to make yours not
work.  Which, knowing MS, is not *impossible* but it's a lot less
likely than their various versions of IE that will break on
http://example.com/graphic.php as a PNG image URL.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] how to display GD graphic in web page

2005-10-24 Thread Jasper Bryant-Greene
On Mon, 2005-10-24 at 20:14 -0400, Chris wrote:
> I don't understand what is going on with a simple example I created to 
> understand how GD graphics are presented in a web page.
[[snip]]
> However if I replace:
> 
> 
> with
> 
>  $image = imagecreatefrompng("my_graphic.png");
> imagepng($image);
> ?> >
> 
> my_graphic.png is no longer displayed and the web page gets filled with 
> random characters.
> 
> Why is this happening or what am I missing.

You're not missing anything. That is exactly the expected behaviour. You
can call graphic.php with GET variables if you need to pass information
on, but you can't put images inline like that except for with data:
URIs.

data: URIs are currently only supported by Gecko browsers (Mozilla,
Firefox, etc) and maybe Safari or Opera (not sure about the latter two).

Do a search for "data: URI RFC" or similar to find out about them.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] how to display GD graphic in web page

2005-10-24 Thread Chris
I don't understand what is going on with a simple example I created to 
understand how GD graphics are presented in a web page.

First I created the following simple script (in a file named graphic.php):

// file: graphic.php


I load that script with my web browser, the image is displayed as expected.

Now if I treat graphic.php as an image, and reference in another page using 
the  tag as in the following:

// my_page.php


Untitled Document






The page again displays my_graphic.png.

However if I replace:


with

 >

my_graphic.png is no longer displayed and the web page gets filled with 
random characters.

Why is this happening or what am I missing.

Thanks for any insight.

Chris 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php