|
Posted by "Chris" on 10/25/05 14:49
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
<script language="php">
class on_the_fly {
function on_the_fly() {
}
function a_graphic() {
$image = imagecreatefrompng("my_graphic.png");
imagepng($image);
}
}
</script>
then call the method as needed as in:
// my_page.php
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<script language="php">
include ('on_the_fly.php');
$otf_graphic = new on_the_fly();
echo "<img src=$otf_graphic->a_graphic()">;
</script>
</body>
</html>
This resulted in a page filled with random characters.
So I interpret from your response that I'm still unable to reference "<img
src=$otf_graphic->a_graphic()"> and MUST create my on-the-fly graphic in a
*.php file or *.png as you suggest.
Thanks
Chris
""Richard Lynch"" <ceo@l-i-e.com> wrote in message
news:59747.71.57.116.88.1130205670.squirrel@www.l-i-e.com...
> 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:
>
> <Files graphic.png>
> ForceType application/x-httpd-php
> </Files>
>
> 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
[Back to original message]
|