Page 1 of 1

imagecreate

Posted: Wed Dec 01, 2004 7:41 pm
by SidewinderX
hello i have this code here:

Code: Select all

<?php

$stat1 = 500;
header ("Content-type: image/png");

$img_handle = ImageCreate (450, 120) or die ("Cannot Create image");

$back_color = ImageColorAllocate ($img_handle, 0, 10, 10);

$txt_color = ImageColorAllocate ($img_handle, 255, 255, 255);

ImageString ($img_handle, 31, 5, 5,  "$stat1", $txt_color);

ImagePng ($img_handle);

?>
...this creates an image with the link http://doamin.com/blah.php .... i want it to create an actual image so the link would be http://doamin.com/blah.png ... how to i do that?

Posted: Wed Dec 01, 2004 8:17 pm
by rehfeld
use htaccess

Code: Select all

RewriteEngine On
RewriteRule blah\.png blah.php

Posted: Wed Dec 01, 2004 8:26 pm
by SidewinderX
..i guess....im looking for more of a php function tho....is there anything like that for php?

Posted: Wed Dec 01, 2004 8:29 pm
by rehfeld
nope

theres other ways to do it, but they still involve using htaccess

php is executed by apache. so if you ask apache for the file blah.png, its going to look for blah.png, unless you tell it otherwise. were telling apache to do otherwise by using mod_rewrite

does your host not support it?

Posted: Wed Dec 01, 2004 8:32 pm
by SidewinderX
well my host does support it and i just tryed it but i couldnt figure out what the image URL was...what does ImageCreateFromPng() do??

Posted: Wed Dec 01, 2004 8:33 pm
by rehfeld

Posted: Wed Dec 01, 2004 8:40 pm
by SidewinderX
...i know... thats where i found the function...but i believe that does what im trying to do...take an image, put some php over the image, and create another new image with the a background and php and store it as a png image...right??

Posted: Wed Dec 01, 2004 9:03 pm
by rehfeld
ohhhh. you want to save the image it creates?

Posted: Wed Dec 01, 2004 10:07 pm
by SidewinderX
yes :D

Posted: Thu Dec 02, 2004 1:26 am
by rehfeld
change your code to

Code: Select all

<?php

ImagePng ($img_handle, 'blah.png');

?>

Posted: Thu Dec 02, 2004 1:35 pm
by SidewinderX
when i change my code (of course substutiting blah.png for the real image) i get an error:
The image “http://192.168.1.123:800/imagecreate/1.php” cannot be displayed, because it contains errors.
im testing it locally hence the 192 address

Posted: Thu Dec 02, 2004 3:12 pm
by rehfeld
http://192.168.1.123:800/imagecreate/1.php

your asking for a php file now, and its no longer outputting the image to your browser, but saving it to a file.


just look in your file system and see if it saved the image or not, or goto the url where you saved the image to

Posted: Thu Dec 02, 2004 3:31 pm
by xisle
you can also add the new image to an image tag ....
or look for it on the server as Rehfeld suggests..
xisle wrote: <snip from old post >

Code: Select all

imagejpeg ($img,"pic.jpg"); 
imagedestroy ($img); 
?>
<center><img src="pic.jpg" border=0></center>