dklassen
dklassen

Reputation: 131

Convert images to GIF

I am attempting to convert a series of JPG files to a single animated GIF. I have done this using the Python script images2gif.py (https://pypi.python.org/pypi/images2gif/1.0.1) It works really well, but I don't know how to make the GIF only run through the images 1 time. I can set the loops=1, which run through it 2 times (i.e. 1 loop) or 0 - which causes it to run infinitly. An suggestions?

Upvotes: 0

Views: 1452

Answers (1)

Basic
Basic

Reputation: 26766

Edit: Only just noticed that @Jongware beat me to it in comments.

The source shows the following:

if loops==0 or loops==float('inf'):
    loops = 2**16-1
    #bb = "" # application extension should not be used
            # (the extension interprets zero loops
            # to mean an infinite number of loops)
            # Mmm, does not seem to work
if True:
    bb = "\x21\xFF\x0B"  # application extension
    bb += "NETSCAPE2.0"
    bb += "\x03\x01"
    bb += intToBin(loops)
    bb += '\x00'  # end
return bb

As you can see, the application extension is always added. From a spec for the extension

bytes 17 to 18 : 0 to 65535, an unsigned integer in lo-hi byte format. This indicate the number of iterations the loop should be executed.

In short, any value will play through a multiple times. It seems the way to avoid this is to omit the extension itself.

if loops != 1:
    bb = "\x21\xFF\x0B"  # application extension
    ...

Upvotes: 3

Related Questions