Git Product home page Git Product logo

node-apng's Introduction

Node APNG

A Node library for stitching Buffers containing PNG image data together to form an APNG image.

This library is based on code by Józef Sokołowski. I've fixed two bugs in it:

  • IDAT chunk CRC calculation was being passed slice range, not the slice buffer
  • PNGs with multiple IDAT chunks only had their first IDAT chunk considered

Usage

npm install tomashubelbauer/node-apng

import apng from 'node-apng';
import fs from 'fs';

const buffers = [/* … */]; // Buffers of PNG image data

// The callback is for frame duration: `numeration/denominator` seconds
const buffer = apng(buffers, index => ({ numerator: 1, denominator: 10 }));
await fs.promises.writeFile('apng.png', buffer);

Support

APNG on GitHub

GitHub repository file preview page will only preview images with a PNG extension, but will animate properly (depending on browser support) if animated.

GitHub MarkDown renderer allows image sources with both PNG and APNG extensions. Will animate properly subject to browser support.

APNG in VS Code

VS Code will correctly preview and animate images as long as they have a PNG extension, not APNG extension.

Development

Use Node 16+ (ESM, TLA)

npm install
cd test
npm start

To-Do

Add a GitHub Action for tests

Refactor as per the code comment

Add support for "skip first frame" to allow "warning this is animated" frame

The first frame should be skipped in the animation and should be a preview with a subtitle which says this is an animated image and your browser doesn't support APNG so you're getting only a preview.

Implement dispose op and blend op to be able to do differential frames

This might cut down on APNG size where the input is a series of screenshots of a screencast video. Most of the screen is likely to remain unchanged. Use Sharp (already referenced) to do the frame comparison and generation of a frame which only contains the changed pixels (and calculation of the change region). Note that transparency support needs to be considered too, probably.

https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk

node-apng's People

Contributors

4i8 avatar talltyler avatar tomashubelbauer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

talltyler 4i8

node-apng's Issues

Sharp Vulnerability

After installation I found it has 2 moderately severe vulnerabilities, I'm kind of hesitant to use it. Can you fix this?

# npm audit report

sharp  <0.30.5
Severity: moderate
sharp vulnerable to Command Injection in post-installation over build environment - https://github.com/advisories/GHSA-gp95-ppv5-3jc5
No fix available
node_modules/sharp
  node-apng
  Depends on vulnerable versions of sharp
  node_modules/node-apng

2 moderate severity vulnerabilities

Some issues need review, and may require choosing
a different dependency.

SyntaxError: Cannot use import statement outside a module

Hi!

It's been some time since I ran this lib with the code I built myself without any issue. Today I was making some refactors and then this error appeared when I tried to run a pod in docker with the same code:

/usr/src/app/node_modules/node-apng/index.js:1
import crc from 'crc';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Module._compile (internal/modules/cjs/loader.js:891:18)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/usr/src/app/br/com/guide-automator/libs/Recorder.js:3:14)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.