About making a random image.

sonicsshadow

Member
Messages
200
Reaction score
0
Points
16
Ok, I have thought about this, and looked at some peoples scripts about how to make a dynamic image. Now, I don't really intend to make one, but it's honestly driving me nuts on how it works.
What I see is, you use the GD library to create a .gif or .png file. It writes variables (lets say you want your image to show your post count on your forum) for your post count to the image. Then you copy the url of the generated image and simply link to it.
But how does it update itself?

Hopefully someone can answer this, because I'm stumped.:dunno:
 

mattura

Member
Messages
570
Reaction score
2
Points
18
Every time you request the image, it runs some code (within it) which uses variables and algorithms to generate the image data, which is returned as an image.
Think of it as having an image with some code at the beginning, which is self-modifying.
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
I'm not sure I get what you mean mattura, but most people use PHP scripts to make dynamic images...
It works like this:
You make a directory "image.png" with all images etc you'll need for your images + an index file "index.php" (PHP has some nice functions to edit images, for more info see http://www.php.net/manual/en/ref.image.php)
This index page has to send the correct headers to the user (image/png) and then it's just a bunch of php codes to generate the right image and send it to the user.

The result of this is an 'image' www.yoursite.com/image.png that is dynamic.

I hope this was helpful,
Marshian
 
Last edited:

sonicsshadow

Member
Messages
200
Reaction score
0
Points
16
Oh I see, so basically you're tricking the browser into thinking the dictionary is an image, then it accesses index.php which creates the image and then it outputs the image?
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
Actually you're not really tricking the browser into anything, it's perfectly normal to send headers other then text/html
but yes, when the browser asks for "image.png", the server knows it's a directory and executes index.php, which sends an image.
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
I'm not sure I get what you mean mattura, but most people use PHP scripts to make dynamic images...
It works like this:
You make a directory "image.png" with all images etc you'll need for your images + an index file "index.php" (PHP has some nice functions to edit images, for more info see http://www.php.net/manual/en/ref.image.php)
This index page has to send the correct headers to the user (image/png) and then it's just a bunch of php codes to generate the right image and send it to the user.

The result of this is an 'image' www.yoursite.com/image.png that is dynamic.

I hope this was helpful,
Marshian

Mattura was talking about generating images from scratch I believe. That is, for the example of an image which displays the post count, php would check the user's current post count and draw an image based on that. Like he said, sort of an image with executable code in it which modifies itself.

Also, you don't need to have a directory named image.png or anything like that. You can specify the source of an image to a php file as long as script outputs an image. This is done all the time with CAPTCHA's.
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
I don't think that was what Mattura ment, he seems to say that images would have some code that would execute when you view them.

And of course you could just use any name for your php script, and refer directly to it (eg. script named "image.php" and your image path "yoursite.com/image.php") but for example in forums, it often happens that the server will ignore these images.
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
I'm fairly certain that's what he meant since the OP asked how the image is updated by the script. And he was saying that algorithms run to generate the image, so of course he's talking about the php. But it doesn't matter.

Anyway, you're right about sites filtering files with non-image extensions. I got confused since there was no mention in this topic of using the generated images on forums or anything like that. So I thought you were saying that that's the way it's always done. I guess we got two different impressions from the question asked.
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
Obviously a flaw in the communication ;-)
But since I think the way with the directory is the best one, due to the server filters, I explained it that way, as it also explains how an image can have a normal image extension (.gif, .png etc) while it's acutally php.
It's also very useful to have your files in a seperate path so you know what belongs where.
 

mattura

Member
Messages
570
Reaction score
2
Points
18
Wow, didn't realise I could be so misleading ;)
I did mean dynamic creation as woiky said, but this discussion has produced a nice alternative suggestion from marshian.

Just to clarify - marshian, were you suggesting the following, for example?
Suppose you want a counter or CAPTCHA-
You have a directory full of images of digits 0-9. You use the php to get the number and construct the count from the digits.
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
Actually I ment every possibility...
You could use a bunch of font/text commands on your image, or you can put one image on top of another, it's all the same.
But just in case you're working with multiple images to generate a dynamic image, directories will make it maintainable.
 
Top