imagecreate

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

imagecreate

Post 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?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

use htaccess

Code: Select all

RewriteEngine On
RewriteRule blah\.png blah.php
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

..i guess....im looking for more of a php function tho....is there anything like that for php?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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?
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post 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??
Last edited by SidewinderX on Wed Dec 01, 2004 8:35 pm, edited 1 time in total.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post 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??
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

ohhhh. you want to save the image it creates?
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

yes :D
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

change your code to

Code: Select all

<?php

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

?>
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post 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
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post 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>
Post Reply