Other

项目介绍

kettek/apng 是一个托管在 GitHub 上的开源项目,主要使用 Go 编写,采用 Other 许可证,目前获得 79 个 Star、12 次 Fork。

仓库全名
kettek/apng
开源许可证
Other
Star 数
79
Fork 数
12
未关闭 Issue
1

README 摘要

APNG golang library This apng package provides methods for decoding and encoding APNG files. It is based upon the work in the official "image/png" package. See apngr for an APNG extraction and combination tool using this library. NOTE: The decoder should work for most anything you throw at it. Malformed PNGs should result in an error message. The encoder currently doesn't handle differences of Image formats and…

完整内容见 GitHub 原始 README 或本页 。

常见问题

apng 用什么语言开发?

主要使用 Go 编写,采用 Other 许可证,目前有 79 个 Star。

apng 可以免费商用吗?

仓库标注的许可证为 Other,商用前请先阅读仓库 LICENSE 文件确认授权范围。

如何获取 apng 的源码?

可以直接克隆仓库:git clone https://github.com/kettek/apng.git,默认分支为 master;安装与运行步骤见仓库 README。

apng 最近还在维护吗?

仓库最近一次更新为 2025年8月27日,当前有 1 个未关闭 Issue;Star 数为 79,可作为社区活跃度的参考。

关于

APNG decoder and encoder for golang

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
104
价值分
51
活跃状态
活跃

语言占比

Go

README

APNG golang library

This apng package provides methods for decoding and encoding APNG files. It is based upon the work in the official “image/png” package.

See apngr for an APNG extraction and combination tool using this library.

NOTE: The decoder should work for most anything you throw at it. Malformed PNGs should result in an error message. The encoder currently doesn’t handle differences of Image formats and similar and has not been tested as thoroughly.

If a regular PNG file is read, the first Frame of the APNG returned by DecodeAll(*File) will be the PNG data.

Types

APNG

The APNG type contains the frames of a decoded .apng file, along with any important properties. It may also be created and used for Encoding.

Signature Description
Frames []Frame The stored frames of the APNG.
LoopCount uint The number of times an animation should be restarted during display. A value of 0 means to loop forever.

Frame

The Frame type contains an individual frame of an APNG. The following table provides the important properties and methods.

Signature Description
Image image.Image Frame image data.
IsDefault bool Indicates if this frame is a default image that should not be included as part of the animation frames. May only be true for the first Frame.
XOffset int Returns the x offset of the frame.
YOffset int Returns the y offset of the frame.
DelayNumerator int Returns the delay numerator.
DelayDenominator int Returns the delay denominator.
DisposeOp byte Returns the frame disposal operation. May be apng.DISPOSE_OP_NONE, apng.DISPOSE_OP_BACKGROUND, or apng.DISPOSE_OP_PREVIOUS. See the APNG Specification for more information.
BlendOp byte Returns the frame blending operation. May be apng.BLEND_OP_SOURCE or apng.BLEND_OP_OVER. See the APNG Specification for more information.

Methods

DecodeAll(io.Reader) (APNG, error)

This method returns an APNG type containing the frames and associated data within the passed file.

Example

package main

import (
  "log"
  "os"
  "github.com/kettek/apng"
)

func main() {
  // Open our animated PNG file
  f, err := os.Open("animation.png")
  if err != nil {
    panic(err)
  }
  defer f.Close()
  // Decode all frames into an APNG
  a, err := apng.DecodeAll(f)
  if err != nil {
    panic(err)
  }
  // Print some information on the APNG
  log.Printf("Found %d frames\n", len(a.Frames))
  for i, frame := range a.Frames {
    b := frame.Image.Bounds()
    log.Printf("Frame %d: %dx%d\n", i, b.Max.X, b.Max.Y)
  }
}

Decode(io.Reader) (image.Image, error)

This method returns the Image of the default frame of an APNG file.

Encode(io.Writer, APNG) error

This method writes the passed APNG object to the given io.Writer as an APNG binary file.

Example

package main

import (
  "image/png"
  "os"
  "github.com/kettek/apng"
)

func main() {
  // Define our variables
  output := "animation.png"
  images := [4]string{"0.png", "1.png", "2.png", "3.png"}
  a := apng.APNG{
    Frames: make([]apng.Frame, len(images)),
  }
  // Open our file for writing
  out, err := os.Create(output)
  if err != nil {
    panic(err)
  }
  defer out.Close()
  // Assign each decoded PNG's Image to the appropriate Frame Image
  for i, s := range images {
    in, err := os.Open(s)
    if err != nil {
      panic(err)
    }
    defer in.Close()
    m, err := png.Decode(in)
    if err != nil {
      panic(err)
    }
    a.Frames[i].Image = m
  }
  // Write APNG to our output file
  apng.Encode(out, a)
}

Custom Compression

A custom compression writer can be used instead of the default zlib writer. This can be done by creating a specific apng Encoder and assigning a construction function to the CompressionWriter field:

enc := apng.Encoder{
	CompressionWriter: func(w io.Writer) (apng.CompressionWriter, error) {
		return NewCustomZlibWriter(w)
	},
}
enc.Encode(out, a)

评论

暂无评论