How do you create an image in code w/header sent already?

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
twrofpwr
Forum Newbie
Posts: 17
Joined: Wed Jun 15, 2005 8:46 pm

How do you create an image in code w/header sent already?

Post by twrofpwr »

Hey guys, how do you create an image in php code with the header already set?

do you create a seperate file like say image.php with only the 2 lines, and then call this image.php from a src tag like this <img src=image.php ?? Does this work? It seems to not be working for me

Also can you get gdlib for use on XP, my laptop is using XP and I have php installed on my laptop.

Thanks guys

//image.php
header("Content-type: image/jpeg");
imagejpeg($_SESSION['current_image']);
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

This done usually with an image tag like this:

Code: Select all

<img src=&quote;image_maker.php?file=someparms&quote;>
image_maker.php makes the image and you use the header() to make the browser think it is an image.

There are some projects that make it easy to have php/apache/mysql on XP

I like xampp at apachefriends.org/en
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

In image.php you need a call to session_start first to make sure $_SESSION data is available...

It should work. (Witness statement from a winxp+apache2+php5+gd2 extension user)
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

yes you can get the gdlib to work.

open your php.ini file and look for the gdlib and remove the ; from in front of it.

save and restart your server.

do a phpinfo to see that it is installed correctly.

the issue may have is the path to your extensions folder.
Post Reply