Creating an image in PHP

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
hider
Forum Newbie
Posts: 7
Joined: Fri Jun 18, 2010 9:11 am

Creating an image in PHP

Post by hider »

I have a script that grabs 9 images from whatever username the person puts in, however, I want instead of a .php file, it to turn as a .jpeg so you can use it on forums etc.

Similar to this: http://4ebq.lastfm.obsessive-media.de/5x5/username.jpeg

Replacing username with your last.fm name returns a 5x5 pictures of your top artists.

At the moment it's just a .php file that displays them as expected, but not sure where to go from here?
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Re: Creating an image in PHP

Post by Phoenixheart »

Not sure I get what you mean, but you can set Apache to treat the .jpg file in a specific directory as PHP. That way you can have a normal image.jpg that gets executed by Apache. Something like image.jpg?id=1
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Creating an image in PHP

Post by McInfo »

@hider: What limitations are you trying to overcome?
hider
Forum Newbie
Posts: 7
Joined: Fri Jun 18, 2010 9:11 am

Re: Creating an image in PHP

Post by hider »

I want to create an image which is 9 other images stacked like a 3x3 box. However these images always change (dynamic).. and I've seen around the web where people use:

Code: Select all

<img src="image.php?user=hider" />
..to create dynamic images with PHP. So I was wondering if I what I want to achieve is possible?
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Creating an image in PHP

Post by McInfo »

It is possible.

It sounds like you have a script that outputs an image correctly when you access a URI like "image.php?user=hider". Is there something keeping you from using that URL as the image source on a forum? I'm not sure what obstacle you are facing.

Does your script output an image or an HTML page with an image on it?
Last edited by McInfo on Mon Jun 21, 2010 6:01 pm, edited 1 time in total.
hider
Forum Newbie
Posts: 7
Joined: Fri Jun 18, 2010 9:11 am

Re: Creating an image in PHP

Post by hider »

McInfo wrote:It is possible.

It sounds like you have a script that outputs an image correctly when you access a URL like "image.php?user=hider". Is there something keeping you from using that URL as the image source on a forum? I'm not sure what obstacle you are facing.

Does your script output an image or an HTML page with an image on it?
Yeah, you are right, however it outputs 9 different images (that form a 3x3 'box of images') in HTML at the moment..
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Creating an image in PHP

Post by McInfo »

Your script needs to send a Content-Type header with an appropriate mime type. After that the script needs to send raw image data in a format that matches the mime type.

To stitch images together, you need to use image functions to create image resources from files and manipulate those resources. Frequently, this is done with PHP's GD library. There are many examples in the manual.

PHP Manual: Image Processing and Generation
Post Reply