lovell / lovell/sharp

`isAnimated` metadata property

Open
#3,984 14 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
JavaScript
Stars
32.7k
Forks
1.4k
Avg merge
1d 14h
Merged PRs (30d)
5

Description

Feature request

What are you trying to achieve?

I need to check whether or not an image is animated (eg animated gif or webp). This may already be possible by checking something like metadata.pages > 1 && (metadata.format === 'gif' || metadata.format === 'webp'), but there may be subtleties that I am not considering, over time other formats such as avif or jxl will come along with animation support too.

Either way, it would be a nice developer experience win to have an easy accessible property for this instead of trying to infer it from the other metadata, is possible. Thoughts?

When you searched for similar feature requests, what did you find that might be related?

Can't quite find a feature request for this, specifically

What would you expect the API to look like?
const {isAnimated} = await sharp('someAnimated.gif').metadata()
console.log(isAnimated) // true

const {isAnimated} = await sharp('someSinglePage.jpg').metadata()
console.log(isAnimated) // false
What alternatives have you considered?

Manually checking the pages property and pairing with format checks, I suppose. PDFs are not animated, but does have pages - so it needs to be more than a pages check I believe?

Please provide sample image(s) that help explain this feature

Shouldn't be necessary for this one.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the metadata() API and the existing pages and format metadata handling. Check how animated GIF and WebP images are represented, along with non-animated images and multi-page PDFs, then determine what a consistent isAnimated result should be for the formats discussed. Done means metadata() exposes the requested boolean without requiring callers to infer it.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
backend, backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.