Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to set webp's loop count if the original picture is a gif with GIF87a type? #381

Open
t00350320 opened this issue Aug 25, 2023 · 2 comments

Comments

@t00350320
Copy link

t00350320 commented Aug 25, 2023

We have a task to transfer a gif(GIF87a, gif1.zip) to webp,
here is our govips demo code:

func main() {
        vips.Startup(nil)
        defer vips.Shutdown()
        p:=vips.NewImportParams()
        p.NumPages.Set(-1)
        imagePath := "gif1.gif"
        buf, err := ioutil.ReadFile(imagePath)  
        imageref,err := vips.LoadImageFromBuffer(buf,p)
        if err !=nil { 
          fmt.Println(err)
        }
        checkError(err)
        //imageref.RemoveMetadata()


        ep := vips.NewDefaultWEBPExportParams()
        image1bytes, _, err := imageref.Export(ep)
        err = ioutil.WriteFile("output.webp", image1bytes, 0644)
        checkError(err)

}

in order to get a thin image, we default use "RemoveMetadata()" before Export to webp, the output webp's loop count is 0 , so the webp loop forever.

Chunk ANIM at offset     30, length     14
  Background color:(ARGB) ff ff ff ff
  Loop count      : 0

if we remove "RemoveMetadata()" , the output is 1, the webp loop once

Chunk ANIM at offset     30, length     14
  Background color:(ARGB) ff ff ff ff
  Loop count      : 1

So,webp "Loop count:" parameter differs with the one that execute "RemoveMetadata()"
, two doubts here:
a:) why RemoveMetadata() affects "Loop count : 0" parameter?
b:) how to set webp's loop count if the original picture is a gif with GIF87a type?
We also tested the normal GIF89a type(gif2.zip) picture with loop 2, it works well when transfered to webp.

FYI:
gif may has two types: GIF87a, GIF89a. While 87a has no reference to loop count and 89a's loop count is set near "0x31d".
For example, 89a type gif (gif2.zip), “31D: 00 00 # Loop forever".
gif89a doc,http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension。

@t00350320
Copy link
Author

gif1.zip

@t00350320 t00350320 changed the title for webp, will RemoveMetadata() keep "Loop count : 0" parameter? how to set webp's loop count if the original picture is a gif with GIF87a type? Aug 28, 2023
@t00350320
Copy link
Author

gif2.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant