In my current problem, I have several hundred animated gifs that will preform a certain animation a few times and then do a different animation the last time. So that means the gif loops 3 times or so then on the 4th time instead of looping it will do a different animation. These loops are all just hardcoded into layers in the .gif file.
My goal is to determine the first loop and shrink the animation into ten frames. I figure that using python, I can find when the first frame equals a later frame (thereby finding the first full sequence and the number of frames). Now I have the number of frames that the animation takes, and this number is variable across the several hundred different images I’m working with. So for one image, the first loop will complete in 20 or so frames, another maybe in 25. Some will take 75 or so frames (since they are a very slow image)
My question is using these numbers (20, 25, 75, … or whatever the first loop is) how can I best turn this into only 10. In my head I did a little math, and these is a good example of what I need to figure out how to generate
20 -> 20/10 = 2 Resulting sequence: [0, 20) step 2
25 -> 25/10 = 2.5 Sequenece: [0, 25).... Step ?? should alternate between 2 and 3 somehow
75 -> 75/10 = 7.5 Sequenece: [0, 75).... Step ?? should alternate between 7 and 8 somehow
My solution could either be in bash script or python or whatever you can use from the bash shell.
Note: shorter solution below
Here’s a Python iterator class that can be used to generate these sequences:
better solution:
It was pointed out to me that there’s a more concise solution using a generator:
You can use it like this: