Skip to content

image/gif: EncodeAll fails to allow non looping animated gif  #15768

@ghost

Description

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go version go1.6.2
  2. What operating system and processor architecture are you using (go env)?
    darwin/amd64
  3. What did you do?
    In package image/gif, I'm trying to use EncodeAll() to create a non-looping animated gif with several frames, but it will always loop. In the GIF specifications 0 means forever, so -1 should the way to go to disable looping, unfortunately setting this value does not work in go.
  4. What did you expect to see?
    I should be able to set LoopCount = -1 and my resulting gif should not loop.
    I want an animated gif, but not a looping animated gif.
  5. What did you see instead?
    My output gif is looping forever (same as LoopCount = 0).

The first problem lies in src/image/gif/write.go

   299      if g.LoopCount < 0 {
   300          g.LoopCount = 0
   301      }

This should be removed to allow a negative value.

The second problem is that Netscape Looping extension header is written in the file whenever there are several frames:

   147      if len(e.g.Image) > 1 {

I believe this should be changed to:

if len(e.g.Image) > 1 && e.g.LoopCount >= 0 {

Another way to fix the problem would be to change the meaning of LoopCount '0' value to actual "no loop", but this could break the expected behaviour for some people. As in other languages, setting -1 sounds ok as long as it's commented somewhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions