sharp icon indicating copy to clipboard operation
sharp copied to clipboard

How to produce animated files from RAW instances in 0.30.0?

Open deftomat opened this issue 3 years ago • 2 comments

We are upgrading Sharp from 0.2*.0 to 0.30.0 and we discovered that pageHeight property on webp() is not supported anymore.

Our use case is:

  1. Load animated image and extract pageHeight
  2. Extract frames from one tall image
  3. Process each frame separately
  4. Compose frames to one tall image
  5. Save as animated file by using pageHeight

The problem is that each frame is processed by multiple steps. Before each step, new Sharp instance is created with new Sharp({ raw: { ... } }) constructor and the previous result is piped into it.

By this, we are probably loosing some kind of metadata which tells Sharp to save image as animated.

Previously, it was easy to tell the Sharp that the result is animated as you need to provide pageHeight and everything worked as expected.

deftomat avatar Apr 12 '22 08:04 deftomat

Hi Tomáš, yes, as a side effect of improved resizing/cropping of animated images, this scenario is now currently unsupported.

Thinking about the right place in the API for this, perhaps adding an animated: true option to the future possible enhancement of #1580 would make sense as that feature would be a better solution to your problem.

lovell avatar Apr 17 '22 10:04 lovell

@lovell Great! I will try to do a PR as we will need it.

deftomat avatar Apr 25 '22 13:04 deftomat

I've added a note to https://github.com/lovell/sharp/issues/1580#issuecomment-464433871 about animated: true - let's track it there.

lovell avatar Sep 05 '22 10:09 lovell