Skip to content

Crytek1012/apng-parser-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

APNG Parser

A simple parser for APNG (Animated Portable Network Graphics) files in Node.js.

Table of Contents

Installation

You can install the apng-parser-js package using npm:

npm install apng-parser-js

Usage

CommonJs:

const { readFileSync } = require('fs');
const apngParser = require('apng-parser-js');

Import:

import { readFileSync } from 'fs';
import apngParser from 'apng-parser-js';

Parse an APNG:

async function parseAPNG(filePath) {
    const buffer = readFileSync(filePath);
    try {
        const apng = apngParser(buffer);
        console.log(apng);
    } catch (err) {
        console.error('Error parsing APNG:', err);
    }
}

parseAPNG('path/to/your/file.png');

Optionally, the raw parameter can be used to retrieve each frame's raw image data:

const apng = apngParser(buffer, {raw: true});

You can directly save the frames by using the APNG method saveFrames():

apng.saveFrames('path-to-your-folder');

Or save a specifc frame by using the Frame method save():

const frame = apng.frames[0];
frame.save('path-to-your-folder');

API

apngParser(buffer: Uint8Array, options): <APNG>

Parses the provided APNG buffer and returns an object containing the metadata of the APNG file.

Parameters

  • buffer: A Buffer containing the binary data of the APNG file.
  • options: The apngParser options

Returns

  • A Promise that resolves to an object containing the APNG metadata.

Example Response

{
  "width": 300,
  "height": 300,
  "frameCount": 4,
  "loopCount": 0,
  "frames": [
    {
      "top": 0,
      "left": 0,
      "width": 300,
      "height": 300,
      "delayNum": 0,
      "delayDen": 0,
      "delay": 100,
      "disposeOp": 1,
      "blendOp": 0,
      "imageData": [Uint8Array]
    },
    // More frames...
  ],
  isRaw: false
}

License

This project is licensed under the ISC License.

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

Author

Created by Crytek1012.

About

A parser for APNG files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published