lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.21k stars 1.29k forks source link

Facing issue on converting formate .dng to .png - Error: Input buffer has corrupt header: tiff2vips: tile size out of range #3971

Closed furkan-wve closed 8 months ago

furkan-wve commented 9 months ago

Current Error

Error converting .dng to .png: Error: Input buffer has corrupt header: tiff2vips: tile size out of range
    at Sharp.toBuffer (../Nodo-demo/node_modules/sharp/lib/output.js:161:17)

Used URL --> https://ovvyfiles.s3.us-east-2.amazonaws.com/listing-image/65b1125d76cb13c2979f2bb8/zmNpg3iUrP7a2OF7tuFC.dng

Possible bug

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

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

Are you using the latest version of sharp?

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 13.5.2 CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz Memory: 1.57 GB / 20.00 GB Shell: 3.2.57 - /bin/bash

Binaries: Node: 21.6.0 - /usr/local/bin/node npm: 10.2.4 - /usr/local/bin/npm

What are the steps to reproduce?

run rpm dev

Error :

Error converting .dng to .png: Error: Input buffer has corrupt header: tiff2vips: tile size out of range
    at Sharp.toBuffer (/Users/wvelabs/Documents/node project/Nodo-demo/node_modules/sharp/lib/output.js:161:17)

What is the expected behaviour?

png image file

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

Calling this function

async function convertDngToPng(dngBuffer, outputFilePath, options = { quality: 80,quality:9 }) {
    try {
        // Use Sharp to read the .dng image and convert it to PNG format with compression
       const  pngImage = await sharp(dngBuffer)
            .png(options) // Set PNG compression options (e.g., quality)
            .toBuffer();

        console.log('Conversion completed successfully.');
        return pngImage;
    } catch (error) {
        console.error('Error converting .dng to .png:', error);
        throw error
    }
}

// Usage example:

            const asyncRequest = promisify(request.get);
            const response = await asyncRequest({ url, encoding: null });
            const dngBuffer = response.body;

            const inputFilePath = 'input.dng'; // Path to the input .dng file
            const outputFilePath = 'output.png'; // Path for the output .png file
            const options = { quality: 80 }; // Compression options (adjust as needed)

           const output = await convertDngToPng(dngBuffer, outputFilePath, options);

note: relevant library required added

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

lovell commented 9 months ago
$ identify -verbose zmNpg3iUrP7a2OF7tuFC.dng 
identify: "dcraw" -c -w -6 -T "zmNpg3iUrP7a2OF7tuFC.dng" > "/tmp/gmPWYMsJ".
Image: zmNpg3iUrP7a2OF7tuFC.dng
  Format: DCRAW
  Geometry: 3024x4032
...

This image is a RAW DNG ("Digital NeGative") masquerading as a TIFF. Please see #616

lovell commented 8 months ago

I hope this information helped. Please feel free to re-open with more details if further assistance is required.