Skip to content

Animated GIF to WEBP using a Sharp stream is not animated anymore #2362

@baptistecs

Description

@baptistecs

The installation went well, and I managed to make it work with a file or an URL for the input and a file for the output, but i don't manage to find a way to get it animated when using a stream for the output.

@deftomat Sorry for bothering you, but I think you might have a quick answer 👼

Are you using the latest version? Is the version currently in use as reported by npm ls sharp the same as the latest version as reported by npm view sharp dist-tags.latest?
Yes

What are the steps to reproduce?

const app = new Koa();
const router = new Router();
const agent = require('superagent');
const sharp = require('sharp');

router.get('/:spec/i.:extension', ctx => {
  let sharpStream = sharp() // WORKING BUT NOT ANIMATED
  let sharpStream = sharp({ animated: true }) // Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
  let sharpStream = sharp({ pages: -1 }) // Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
  let sharpStream = sharp(undefined, { pages: -1 }) // Error: Unsupported input 'undefined' of type undefined when also providing options of type object
  let sharpStream = sharp(undefined, { animated: true }) // Error: Unsupported input 'undefined' of type undefined when also providing options of type object

  sharpStream = sharpStream.toFormat('webp', {
    quality,
    pages: -1, // doesn't change anything
    animated: true, // doesn't change anything
  });

  ctx.set('Content-Type', 'image/webp');
  ctx.body = agent.get(url).pipe(sharpStream);
  ctx.status = 200;
});

What is the expected behaviour?
The output stream webp image should be animated.

Are you able to provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem?
Kind of, please see below.

Are you able to provide a sample image that helps explain the problem?
I used this image.

What is the output of running npx envinfo --binaries --system?

  System:
    OS: macOS 10.15.6
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 12.02 GB / 32.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.22.0 - ~/.nvm/versions/node/v10.22.0/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v10.22.0/bin/npm

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions