Page 1 of 2
Looking for a way to store temporary images
Posted: Sat Jul 15, 2006 9:01 pm
by Trenchant
I've run into a problem with a site I'm working on. I need to dynamically create a car by starting with a body, loading from a mysql database about 10 different parts and assembling everything. The only thing is a user then needs to be able to see this car on every page they go to AND this whole process needs to occur with hundreds of different cars for every user every hour...
So I'm thinking the best thing to do is create the img when the user logs in and store it in a session. The only thing is, is this possible? It wouldn't be efficient enough to save the image on the server.
Another problem is in actually creating the image. How can I accurately state using pixels where I want parts to appear before finalizing the graphic and sending it the user?
Thanks
Posted: Sun Jul 16, 2006 1:49 am
by s.dot
I don't think you can use sessions for storing an image resource
php.net wrote:Some types of data can not be serialized thus stored in sessions. It includes resource variables or objects with circular references (i.e. objects which passes a reference to itself to another object).
Posted: Sun Jul 16, 2006 3:08 am
by Jenk
Create lots of smaller images.
A different image, for a different part, in different colours.
Give each image an ID, and store the path in a db.
Track which options (images) the user picks... then use GD lib to impose the images ontop one another to give the complete car image.
I'm assuming this is a 'pick and choose your car and trimming colour' style site

Posted: Sun Jul 16, 2006 11:09 am
by bokehman
One possible way: There is no need to create the final image at all. You can do that with css. For more details check
this out. It just stacks the images one ontop of the other.
Posted: Wed Jul 19, 2006 9:44 am
by Trenchant
Would creating the image every time the user loads the page still be resourseful? There will be two views of a users car, the front and the side. One or the other is planned to be shown on every page. If there were say 1000 users online at once wouldn't that be really hard on the servers?
bokehman wrote:One possible way: There is no need to create the final image at all. You can do that with css. For more details check
this out. It just stacks the images one ontop of the other.
Ya that was the other way I was thinking of doing it. Haven't seen it done with CSS though... I'll have to look at that more closely once I get back from work.
Posted: Wed Jul 19, 2006 2:51 pm
by bokehman
Web Dummy wrote:Would creating the image every time the user loads the page still be resourseful? There will be two views of a users car, the front and the side.
Lets say you had 10 features with 10 choices in each; that is 10^10 or put another way 10 billion combinations. Add a few more choices and possibilites and you are talking an infinite number of images. Caching is just going to fill your hard drive with images that will probably only ever be requested once.
Storing the image in the session would work though and if you need code for this I'd be happy to help you out.
If though they already had downloaded the images of the parts to local in order to choose them my method above should work fine.
Posted: Wed Jul 19, 2006 3:04 pm
by Ward
Here's one thought. Store the actual image data (not the resource, but the file contents) in a BLOB field in a database. Then you can categorize them much better and easier than files. You'll need some sort of image viewer script, which would be called like '<img src="view_image.php?imageID=1">'.
When it's time to load an image, simply select the image data into a string. Then use imagecreatefromstring(), and imagejpeg() or imagepng() to display the image.
Posted: Wed Jul 19, 2006 3:42 pm
by Ollie Saunders
bokehman wrote:Lets say you had 10 features with 10 choices in each; that is 10^10 or put another way 10 billion combinations.
I think you mean 10*10 and that's only 100.
Posted: Wed Jul 19, 2006 3:56 pm
by bokehman
ole wrote:bokehman wrote:Lets say you had 10 features with 10 choices in each; that is 10^10 or put another way 10 billion combinations.
I think you mean 10*10 and that's only 100.
No, no, no! That would be two items with a choice of 10 in each. If there are 10 items with 10 choices in each that is:
10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10
or
10^10
or
10 billion
Posted: Wed Jul 19, 2006 4:01 pm
by Luke
10 items with 10 choices each isn't 10 billion man. It's 100.
Posted: Wed Jul 19, 2006 4:41 pm
by Ollie Saunders
No, no, no! That would be two items with a choice of 10 in each
Ah yeah i think you might be right actually. sorry.
Posted: Wed Jul 19, 2006 4:58 pm
by bokehman
The Ninja Space Goat wrote:10 items with 10 choices each isn't 10 billion man. It's 100.
I do hate being told I am wrong when I am right so I have
prepared a page which will prove I am right to all those that have trouble with simple arithmetic.
Posted: Wed Jul 19, 2006 5:04 pm
by bokehman
;;
Posted: Wed Jul 19, 2006 5:04 pm
by Ollie Saunders
bokehman wrote:The Ninja Space Goat wrote:10 items with 10 choices each isn't 10 billion man. It's 100.
I do hate being told I am wrong when I am right so I have
prepared a page which will prove I am right to all those doubting Thomases that have trouble with simple arithmetic.
hehe that's fun. ahem sorry i ever doubted you.
Posted: Wed Jul 19, 2006 5:07 pm
by bokehman
ole wrote:hehe that's fun. ahem sorry i ever doubted you.
Yeah! Sometimes things are a lot easier to see with a demo.