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
28.97k stars 1.29k forks source link

Error: Input buffer has corrupt header #3191

Closed Jawell closed 2 years ago

Jawell commented 2 years ago

Question about an existing feature

What are you trying to achieve?

Using sharp But I get this error:

Error: Input buffer has corrupt header: magickload_buffer: Magick: improper image header `' @ error/tga.c/ReadTGAImage/219 (null)

libvips installed globally by brew, but I tried to use from sharp

ImageMagick 7.1.0-29 Q16-HDRI x86_64 19841
vips-8.12.2-Tue Jan 25 09:34:32 UTC 2022

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

Nothing

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

import { ReadStream } from 'fs-capacitor';

async optimizeImage(inputStream: ReadStream) {
    const transform = sharp();
    console.log(await inputStream.pipe(transform).metadata());
}
  {
    jpeg: {
      id: 'jpeg',
      input: { file: true, buffer: true, stream: true },
      output: { file: true, buffer: true, stream: true }
    },
    png: {
      id: 'png',
      input: { file: true, buffer: true, stream: true },
      output: { file: true, buffer: true, stream: true }
    },
    webp: {
      id: 'webp',
      input: { file: true, buffer: true, stream: true },
      output: { file: true, buffer: true, stream: true }
    },
    tiff: {
      id: 'tiff',
      input: { file: true, buffer: true, stream: true },
      output: { file: true, buffer: true, stream: true }
    },
    magick: {
      id: 'magick',
      input: { file: true, buffer: true, stream: true },
      output: { file: true, buffer: true, stream: true }
    },
    openslide: {
      id: 'openslide',
      input: { file: true, buffer: false, stream: false },
      output: { file: false, buffer: false, stream: false }
    },
    dz: {
      id: 'dz',
      input: { file: false, buffer: false, stream: false },
      output: { file: true, buffer: true, stream: true }
    },
    ppm: {
      id: 'ppm',
      input: { file: true, buffer: false, stream: false },
      output: { file: true, buffer: false, stream: false }
    },
    fits: {
      id: 'fits',
      input: { file: true, buffer: false, stream: false },
      output: { file: true, buffer: false, stream: false }
    },
    gif: {
      id: 'gif',
      input: { file: true, buffer: true, stream: true },
      output: { file: true, buffer: true, stream: true }
    },
    svg: {
      id: 'svg',
      input: { file: true, buffer: true, stream: true },
      output: { file: false, buffer: false, stream: false }
    },
    heif: {
      id: 'heif',
      input: { file: true, buffer: true, stream: true },
      output: { file: true, buffer: true, stream: true }
    },
    pdf: {
      id: 'pdf',
      input: { file: true, buffer: true, stream: true },
      output: { file: false, buffer: false, stream: false }
    },
    vips: {
      id: 'vips',
      input: { file: true, buffer: false, stream: false },
      output: { file: true, buffer: false, stream: false }
    },
    jp2k: {
      id: 'jp2k',
      input: { file: true, buffer: true, stream: true },
      output: { file: true, buffer: true, stream: true }
    },
    raw: {
      id: 'raw',
      input: { file: false, buffer: true, stream: true },
      output: { file: false, buffer: true, stream: true }
    }
  }
System:
    OS: macOS 12.3.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 347.24 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.3 - ~/.nvm/versions/node/v14.17.3/bin/node
    Yarn: 1.22.18 - ~/.nvm/versions/node/v14.17.3/bin/yarn
    npm: 6.14.13 - ~/.nvm/versions/node/v14.17.3/bin/npm
  npmPackages:
    sharp: ^0.30.3 => 0.30.3 
lovell commented 2 years ago

Please provide a sample image that generates this error.

Jawell commented 2 years ago

Hi @lovell ! I used this images:

Images ![golden-fish(p)](https://user-images.githubusercontent.com/21054523/163672055-5c18793b-a2a2-4ba8-bfa5-1cde2cdc5c57.jpg) ![boromir](https://user-images.githubusercontent.com/21054523/163672061-d1216d72-4619-4053-b95c-de1487d65642.jpg) ![Optical-setup-of-the-holographic-stereogram-printing-system-a-and-images-of-optical](https://user-images.githubusercontent.com/21054523/163672068-ee17f4c8-ca6a-41ed-a05c-c19bca741e2a.png)

Archive of this images: Images.zip

lovell commented 2 years ago

These images appear to be valid so I'm unsure what's happening here. Is there a reason you need to use the brew-installed vips package rather than the prebuilt binaries provided by sharp? Perhaps run brew update && brew upgrade to ensure you're using the latest version of everything.

Jawell commented 2 years ago

Thank you. I tried to use sharp with prebuild vips by deleting vips in brew, but this didn't work (of course with reinstalling sharp in project). Now, I decide to delete all my brew packages, not only vips because I don't have necessary packages. It's work, and it doesn't matter to me which package (prebuild or global) to use. I don't no what is the problem of brew vips

MikhailShumenko commented 3 months ago

So, what was the fix, guys?