Skip to content

Can't make GIFs work properly #173

@ivanjaros

Description

@ivanjaros

I am, unable to produce proper gifs, there are always artifacts or loss of visual quality, even if gif is encoded without errors. I saw examples here and am processing individual frames but the result is always garbage. Changing filters did not help either. Any idea why?

                        g, err := gif.DecodeAll(src)
			if err != nil {
				return err
			}

			if len(g.Image) == 0 {
				_, err := io.Copy(dst, src)
				return err
			}

			g.Config.Width = 0
			g.Config.Height = 0

			for k := range g.Image {
				for j := range rules {
					if result, ok := rules[j].Apply(g.Image[k], filter).(*image.NRGBA); ok {
						g.Image[k] = &image.Paletted{
							Pix:     result.Pix,
							Stride:  result.Stride,
							Rect:    result.Rect,
							Palette: g.Image[k].Palette,
						}
					}
				}
				if g.Image[k].Bounds().Max.X > g.Config.Width || g.Image[k].Bounds().Max.Y > g.Config.Height {
					g.Config.Width = g.Image[k].Bounds().Max.X
					g.Config.Height = g.Image[k].Bounds().Max.Y
				}
			}

			return gif.EncodeAll(dst, g)

I have just one resize rule for testing(called by the Apply).

The source is random gif from the internet with 800x600 dimensions and I am testing resizing to half.

Source:
source

Result(also 3x in file size)
dst

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions