Page 1 of 1
Creating an image in PHP
Posted: Mon Jun 21, 2010 10:18 am
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?
Re: Creating an image in PHP
Posted: Mon Jun 21, 2010 10:47 am
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
Re: Creating an image in PHP
Posted: Mon Jun 21, 2010 2:16 pm
by McInfo
@hider: What limitations are you trying to overcome?
Re: Creating an image in PHP
Posted: Mon Jun 21, 2010 4:00 pm
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?
Re: Creating an image in PHP
Posted: Mon Jun 21, 2010 5:57 pm
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?
Re: Creating an image in PHP
Posted: Mon Jun 21, 2010 6:01 pm
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..
Re: Creating an image in PHP
Posted: Mon Jun 21, 2010 6:11 pm
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