Page 1 of 1

image creation

Posted: Wed Oct 02, 2002 7:48 am
by Coca-Bear
hi all again, i have a little prob. :p

i'm trying to learn imagecreate()

i know my webhoster supports gd library cause it says in phpinfo();

GD Support enabled
GD Version 1.6.2 or higher
FreeType Support enabled
FreeType Linkage with freetype
JPG Support enabled
PNG Support enabled
WBMP Support enabled

but when i try this(from a tutorial)

Code: Select all

<HTML>
<HEAD>
<TITLE> Images Creation </TITLE>
</HEAD>
<BODY>

<?php
Header("Content-Type: image/jpg");
$im = ImageCreate(100, 100);
$black = ImageColorAllocate($im, 0, 0, 0);
$white = ImageColorAllocate($im, 255, 255, 255);
ImageLine($im, 1, 1, 99, 99, $white);
Imagejpeg($im);
ImageDestroy($im);
?>

</BODY>
</HTML>
when i load up image.php it asks for me to download the file? i can view other php. files prefectly. but not this one.

when i tried include it sometimes ask me to download the file. or comes up with alot of weird characters.

help? :p

i'm using f2o as my hoster. and they have php 4.2.2.

Thanks

Coca-Bear

Posted: Wed Oct 02, 2002 7:53 am
by twigletmac
Try changing this:

Code: Select all

image/jpg
to this

Code: Select all

image/jpeg
Mac

Posted: Wed Oct 02, 2002 8:00 am
by Coca-Bear
ok i tried that mac. the whole page loads. but no pic is showing. no X or anything.

i tried an even simplier ImageCreate()

Code: Select all

<?
Header("Content-Type: image/jpg");
$im = ImageCreate(500, 75);
$red = ImageColorAllocate($im, 255, 100, 0);
ImageFill($im, 100, 100, $red);
ImageJPG($im);
?>
again loads. but no pic.

Thanks

Coca-Bear

Posted: Wed Oct 02, 2002 8:04 am
by twigletmac
Try removing that HTML stuff you've got so that all you have in the page is:

Code: Select all

<?php 
Header("Content-Type: image/jpeg"); 
$im = ImageCreate(100, 100); 
$black = ImageColorAllocate($im, 0, 0, 0); 
$white = ImageColorAllocate($im, 255, 255, 255); 
ImageLine($im, 1, 1, 99, 99, $white); 
Imagejpeg($im); 
ImageDestroy($im); 
?>
This works as it should for me.

Mac

Posted: Wed Oct 02, 2002 8:11 am
by Coca-Bear
ok that worked. :p

Thanks for the help

Coca-Bear

Posted: Wed Oct 02, 2002 8:13 am
by Coco
so that only works on a page with no html?

meaning that if i wanted to put that image within a page i would need to save the resulting picture somewhere?

Posted: Wed Oct 02, 2002 8:20 am
by twigletmac
You can put the image into your page like you would a normal image:

Code: Select all

<img src="test.php" alt="PHP generated image" />
But if you're going to display the same image a lot it would make sense to take the load off the server and save the resulting picture as a normal jpeg (or whatever) and use that instead of dynamically generating it each time.

Mac

Posted: Wed Oct 02, 2002 8:22 am
by volka
one http-request is exactly that, _one_ document.
If you have an picture 'within' your html-document that are two http-requests. First the html-document (the browser parses this, finds the <img>-element and requests) then the image 'document'.

If you open the "source view" for a HTML-doc in your browser you won't see any picture data, only the <img>-element having a src-attribute that contains the url for the document that contains the data. [still ignoring <img src="data:image/gif;base64,..... syntax ;) ]