Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrupted AVIF image when using chromaSubsampling 4:2:0 and lossless: true on 0.33.5 #4327

Open
3 of 5 tasks
abarre opened this issue Feb 13, 2025 · 1 comment
Open
3 of 5 tasks

Comments

@abarre
Copy link

abarre commented Feb 13, 2025

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.

Sharp 0.33.5 is affected but other previous versions are fine.

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

System:
    OS: macOS 14.2
    CPU: (8) arm64 Apple M3
    Memory: 1.76 GB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
  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?

What is the expected behaviour?

With 0.33.5, the output image is completely black.

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

const sharp = require('sharp');
const path = require('path');
const fs = require('fs');

// Function to convert an image to AVIF
async function convertToAvif(inputPath) {
  try {
    // Ensure the input file exists
    if (!fs.existsSync(inputPath)) {
      console.error('Input file does not exist:', inputPath);
      return;
    }

    // Convert the image to AVIF format
    await sharp(inputPath).avif({ lossless: true, chromaSubsampling: '4:2:0' }).toFile('output.avif');

    console.log(`Image successfully converted`);
  } catch (error) {
    console.error('Error converting image to WEBP:', error.message);
  }
}

// Replace with your input and output file paths
const inputImagePath = path.resolve(__dirname, 'input.jpg'); // Adjust the filename and extension
// const outputImagePath = path.resolve(__dirname, 'output.latestsharp.webp');

// Call the conversion function
convertToAvif(inputImagePath);

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

input image :
Image

@abarre abarre added the triage label Feb 13, 2025
@lovell
Copy link
Owner

lovell commented Feb 13, 2025

Please see the upstream libvips issue for this at libvips/libvips#4232 - this will be part of the future libvips v8.16.1, which sharp will include as part of the future v0.34.0.

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

No branches or pull requests

2 participants