1.0.6 • Published 10 months ago

apng-parser-js v1.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

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.

1.0.6

10 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago