Skip to content

PNG with Adobe-specific binary metadata unexpectedly increased size #4328

Closed

Description

@styfle

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

  • Running npm install sharp completes without error.
  • Running node -e "require('sharp')" completes without error.

If you cannot confirm both of these, please open an installation issue instead.

Are you using the latest version of sharp?

  • I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.

If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.

If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

  System:
    OS: macOS 15.3
    CPU: (11) arm64 Apple M3 Pro
    Memory: 60.09 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.13.0 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.9.2 - /usr/local/bin/npm
    pnpm: 9.15.0 - /usr/local/bin/pnpm
    bun: 1.2.0 - /opt/homebrew/bin/bun
  npmPackages:
    sharp: ^0.33.5 => 0.33.5 

Does this problem relate to file caching?

The default behaviour of libvips is to cache input files, which can lead to EBUSY or EPERM errors on Windows.
Use sharp.cache(false) to switch this feature off.

  • Adding sharp.cache(false) does not fix this problem.

Does this problem relate to images appearing to have been rotated by 90 degrees?

Images that contain EXIF Orientation metadata are not auto-oriented. By default, EXIF metadata is removed.

  • To auto-orient pixel values use the parameter-less rotate() operation.

  • To retain EXIF Orientation use keepExif().

  • Using rotate() or keepExif() does not fix this problem.

What are the steps to reproduce?

// index.mjs
import sharp from 'sharp';
const res = await fetch('https://png-sharp.vercel.app/input.png');
const input = await res.bytes();
const output = await sharp(input).resize(300).png({quality: 10}).toBuffer();
console.log({ input: input.byteLength, output: output.byteLength });

What is the expected behaviour?

Expected output to be smaller than input

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem

// index.mjs
import sharp from 'sharp';
const res = await fetch('https://png-sharp.vercel.app/input.png');
const input = await res.bytes();
const output = await sharp(input).resize(300).png({quality: 10}).toBuffer();
console.log({ input: input.byteLength, output: output.byteLength });

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

https://png-sharp.vercel.app/input.png

Activity

  1. lovell commented on Feb 14, 2025

    @lovell
    Owner

    The input image contains a lot of metadata, including 13986627 bytes of an Adobe-specific binary tag.

    $ exiftool input.png
    ...
    Raw Profile Type Tiff 37724     : (Binary data 13986627 bytes, use -b option to extract)
    ...
    

    These get handled internally by libvips as PNG "comments". However there was a bug in libvips 8.15 that fails to remove these and then re-encodes from binary to text, making the file size larger.

    This was reported in libvips/libvips#4224 and fixed in libvips/libvips#4225 and the prebuilt libvips binaries provided by the future sharp v0.34.0 will introduce the fix.

  2. added this to the v0.34.0 milestone on Feb 14, 2025
  3. changed the title [-]PNG resized and reduced quality unexpectedly increased size[/-] [+]PNG with Adobe-specific binary metadata unexpectedly increased size[/+] on Feb 14, 2025
  4. lovell commented on Apr 4, 2025

    @lovell
    Owner

    sharp v0.34.0 now available with the upstream fix, thanks for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions