Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
No such thing as a small change
 
PerlMonks  

Re: Creating an animated gif with GD

by BrowserUk (Pope)
on Aug 22, 2010 at 02:39 UTC ( #856541=note: print w/ replies, xml ) Need Help??


in reply to Creating an animated gif with GD

but am still curious as to why GD doesn't work for me.

Because you're using it wrong :).

First, you are accumulating the frames in  $gifdata .= $frame->gifanimadd;, but then you print just the header info from the image into the file: print F $img->gif();.

You should be printing the accumulated headers and frame data to the file: print F $gifdata;

That doesn't affect a complete fix though because you're also confusing what constitutes a frame and what a complete animation. That is, you appear to be drawing a complete set of moving rectangles into each frame, rather than one rectangle at a different position in each frame.

You should also check that each frame, when viewed as a discrete image, actually displays what you think you are drawing in that frame..

And finally, you need to ensure that all the colors you use in the frames, are added to the palette of the base image, before you capture the header with gifanimbegin()


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: Creating an animated gif with GD
Select or Download Code
Re^2: Creating an animated gif with GD
by punkish (Priest) on Aug 22, 2010 at 12:41 UTC
    First, you are accumulating the frames in $gifdata .= $frame->gifanimadd;, but then you print just the header info from the image into the file: print F $img->gif();. You should be printing the accumulated headers and frame data to the file: print F $gifdata;
    Silly me, of course, I was doing it wrong. It is all working now, many thanks. Oh, and GD is about an order of magnitude faster than Imager. This would make a significant difference when I work with real data... 100 years worth (iow, 100 frames) of a few hundred thousand to a couple of million cells.
    That doesn't affect a complete fix though because you're also confusing what constitutes a frame and what a complete animation. That is, you appear to be drawing a complete set of moving rectangles into each frame, rather than one rectangle at a different position in each frame.
    No, thankfully, I got that part right.

    Now I have to figure out whether an animated gif is appropriate for me (pretty universal readability... all browsers can), or if I should go the route of HTML5 video. What I would really like is a user-controllable scrub/scroll bar so the time-lapse can be changed to any time period. But, that is not a perl problem...

    Many thanks again.

    --

    when small people start casting long shadows, it is time to go to bed

      Is there any chance I could see the Imager version of the code?

      I'm curious about the performance difference.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://856541]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (13)
As of 2014-04-17 10:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (444 votes), past polls