Looking for a way to store temporary images

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

User avatar
Trenchant
Forum Contributor
Posts: 291
Joined: Mon Nov 29, 2004 6:04 pm
Location: Web Dummy IS

Looking for a way to store temporary images

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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).
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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 :)
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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.
User avatar
Trenchant
Forum Contributor
Posts: 291
Joined: Mon Nov 29, 2004 6:04 pm
Location: Web Dummy IS

Post 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.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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.
Ward
Forum Commoner
Posts: 74
Joined: Thu Jul 13, 2006 10:01 am

Post 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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

10 items with 10 choices each isn't 10 billion man. It's 100.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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.
Last edited by bokehman on Wed Jul 19, 2006 5:04 pm, edited 1 time in total.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

;;
Last edited by bokehman on Wed Jul 19, 2006 5:05 pm, edited 1 time in total.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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.
Post Reply