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

Different orientation between avif and jpeg/webp #4289

Open
3 tasks done
abarre opened this issue Dec 5, 2024 · 1 comment
Open
3 tasks done

Different orientation between avif and jpeg/webp #4289

abarre opened this issue Dec 5, 2024 · 1 comment

Comments

@abarre
Copy link

abarre commented Dec 5, 2024

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 14.2
    CPU: (8) arm64 Apple M3
    Memory: 88.81 MB / 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

What are the steps to reproduce?

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).keepMetadata().toFile('output.keepMetadata.jpeg');
    await sharp(inputPath).keepMetadata().toFormat('avif').toFile('output.keepMetadata.avif');
    await sharp(inputPath).keepMetadata().toFormat('webp').toFile('output.keepMetadata.webp');
    await sharp(inputPath).withMetadata().toFile('output.withMetadata.jpeg');
    await sharp(inputPath).withMetadata().toFormat('avif').toFile('output.withMetadata.avif');
    await sharp(inputPath).withMetadata().toFormat('webp').toFile('output.withMetadata.webp');
    await sharp(inputPath).toFile('output.jpeg');
    await sharp(inputPath).toFormat('avif').toFile('output.avif');
    await sharp(inputPath).toFormat('webp').toFile('output.webp');
    await sharp(inputPath).rotate().toFile('output.rotate.jpeg');
    await sharp(inputPath).rotate().toFormat('avif').toFile('output.rotate.avif');
    await sharp(inputPath).rotate().toFormat('webp').toFile('output.rotate.webp');
    await sharp(inputPath).keepExif().toFile('output.keepExif.jpeg');
    await sharp(inputPath).keepExif().toFormat('avif').toFile('output.keepExif.avif');
    await sharp(inputPath).keepExif().toFormat('webp').toFile('output.keepExif.webp');

    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);

What is the expected behaviour?

I expect to see the correct orientation for all output images. However, I see error only for AVIF format

The only case when AVIF format is correctly oriented is when using rotate().

JPEG :

.keepMetadata().toFile('output.keepMetadata.jpeg'); => OK
.withMetadata().toFile('output.withMetadata.jpeg'); => OK
.toFile('output.jpeg'); => KO
.rotate().toFile('output.rotate.jpeg'); => OK
.keepExif().toFile('output.keepExif.jpeg'); => OK

WEBP

.keepMetadata().toFile('output.keepMetadata.webp'); => OK
.withMetadata().toFile('output.withMetadata.webp'); => OK
.toFile('output.webp'); => KO
.rotate().toFile('output.rotate.webp'); => OK
.keepExif().toFile('output.keepExif.webp'); => OK

AVIF

.keepMetadata().toFile('output.keepMetadata.avif'); => KO
.withMetadata().toFile('output.withMetadata.avif'); => KO
.toFile('output.avif'); => KO
.rotate().toFile('output.rotate.avif'); => OK
.keepExif().toFile('output.keepExif.avif'); => KO

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

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

input

@lovell
Copy link
Owner

lovell commented Dec 8, 2024

Thanks for reporting, I've opened an upstream PR with a possible fix for this at libvips/libvips#4314

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