PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Sun Nov 29, 2020 8:34 am

All times are UTC - 5 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Jul 19, 2011 4:41 am 
Forum Newbie

Joined: Tue Jul 19, 2011 4:33 am
Posts: 1
Dear All,

Couldn't find anything about this topic.
I have an animated GIF that contains a tree picture which changes color over time. What I'd like to accomplish is that if a website visitor clicks on a link and the page is being reloaded, the GIF Tree doesn't start again from the beginning. No, the Tree should have the color which it had when the user clicked on the link. So I'd like to store the frame number of the GIF when the user clicks a link and starts the GIF animation on the reloaded page with that frame number. Is that possible at all? The only image library for PHP I have is GD. THink there's no ImageMagick on this server.

Thanks for your help on this!
Best regards,

PostPosted: Tue Jul 19, 2011 10:23 pm 
DevNet Resident
User avatar

Joined: Wed Apr 01, 2009 1:31 pm
Posts: 1532
There is no way to "bookmark" a GIF, so making the animation start at a specific frame involves reordering the frames. That could result in graphical anomalies because a frame may rely on the cumulative changes made to the so-called "logical screen" by all the frames before it. Also, changes to the image file would be seen by all users. And it would be unnecessarily resource-intensive to modify an image so frequently.

Depending on the number of frames, it might be practical to create a cache of separate GIFs (using a graphics program) that start at different frames.

You still have the problem of knowing what frame the animation is on. That could be solved by maintaining a counter in JavaScript with a timeout or interval that begins when the image is loaded. Image objects have an onload method that is called when the image has finished loading. The timeout or interval would need to be synchronized with the frame delay. I wouldn't expect that to be totally reliable.

An alternative might be to represent each frame with a separate file (not necessarily GIF) and use JavaScript to animate them. The frame counter would be more reliable this way. The images would need to be pre-loaded.

Network delays should be a consideration.

Are you able to share the image? Seeing it might help us better understand the situation and inspire some creative solutions.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group