vips jpegsave logs a warning while sharp handles it as error
Possible bug
Is this a possible bug in a feature of sharp, unrelated to installation?
- [ x] Running
npm install sharpcompletes without error. - [x ] 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?
- [ x] I am using the latest version of
sharpas reported bynpm 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.4.1 CPU: (12) arm64 Apple M2 Pro Memory: 80.28 MB / 32.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node Yarn: 1.22.22 - /opt/homebrew/bin/yarn npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm pnpm: 8.15.6 - /opt/homebrew/bin/pnpm npmPackages: sharp: ^0.33.4 => 0.33.4
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.
- [ x] 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(). -
[x ] Using
rotate()orkeepExif()does not fix this problem.
What are the steps to reproduce?
I have an obviously somewhat corrupt jpeg, since it throws the error VipsJpeg: Premature end of JPEG file on the .toBuffer() command in my nodejs code.
When I run VIPS_INFO=true vips jpegsave corrupt.jpg test.jpg --Q=80 on command line, I also get the message, but as a warning.
What is the expected behaviour?
I would expect the same log level in sharp as in vips jpegsave command. If it were the same level, the problem would not occur, since we set the option failOn to "error".
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
———————————————————————————————————————————————— Output console vips jpegsave ————————————————————————————————————————————————
Command —————— VIPS_INFO=true vips jpegsave corrupt.jpg test.jpg --Q=80
Log —————— VIPS-INFO: 15:14:01.647: found /opt/homebrew/Cellar/vips/8.15.2_1/lib/vips-modules-8.15 VIPS-INFO: 15:14:01.649: using configure-time prefix VIPS-INFO: 15:14:01.649: VIPS_PREFIX = /opt/homebrew/Cellar/vips/8.15.2_1 VIPS-INFO: 15:14:01.649: VIPS_LIBDIR = /opt/homebrew/Cellar/vips/8.15.2_1/lib VIPS-INFO: 15:14:01.649: prefix = /opt/homebrew/Cellar/vips/8.15.2_1 VIPS-INFO: 15:14:01.649: libdir = /opt/homebrew/Cellar/vips/8.15.2_1/lib VIPS-INFO: 15:14:01.652: searching "/opt/homebrew/Cellar/vips/8.15.2_1/lib/vips-modules-8.15" VIPS-INFO: 15:14:01.652: loading "/opt/homebrew/Cellar/vips/8.15.2_1/lib/vips-modules-8.15/vips-heif.dylib" VIPS-INFO: 15:14:01.665: loading "/opt/homebrew/Cellar/vips/8.15.2_1/lib/vips-modules-8.15/vips-magick.dylib" VIPS-INFO: 15:14:01.670: loading "/opt/homebrew/Cellar/vips/8.15.2_1/lib/vips-modules-8.15/vips-poppler.dylib" VIPS-INFO: 15:14:01.686: loading "/opt/homebrew/Cellar/vips/8.15.2_1/lib/vips-modules-8.15/vips-openslide.dylib" VIPS-INFO: 15:14:01.693: loading "/opt/homebrew/Cellar/vips/8.15.2_1/lib/vips-modules-8.15/vips-jxl.dylib" VIPS-INFO: 15:14:01.698: searching "/opt/homebrew/Cellar/vips/8.15.2_1/lib/vips-plugins-8.15" VIPS-INFO: 15:14:01.700: im_load_plugins: searching "/opt/homebrew/Cellar/vips/8.15.2_1/lib/vips-8.15"
VIPS-INFO: 15:14:01.701: im_load_plugins: searching "/opt/homebrew/Cellar/vips/8.15.2_1/lib"
VIPS-INFO: 15:14:01.717: threadpool completed with 4 workers
(vips:1172): VIPS-WARNING **: 15:14:01.717: read gave 1 warnings
(vips:1172): VIPS-WARNING **: 15:14:01.717: VipsJpeg: Premature end of JPEG file
———————————————————————————————————————————————— Sharp ————————————————————————————————————————————————
Code ——— const image = sharp(fileBufferToUse, { failOn: 'error' }); image.normalise(); image.jpeg({ quality: 80, mozjpeg: true, optimizeScans: true }); image.rotate(); image.toBuffer((err, buffer, info) => { console.log('info', info); console.log('error', err); return buffer; });
Error ——— Error: VipsJpeg: Premature end of input file VipsJpeg: Premature end of input file at Sharp.toBuffer (/Users/aaa/Dev/Repos/convenience-platform/node/document-storage-service/node_modules/.pnpm/[email protected]/node_modules/sharp/lib/output.js:161:17)
Please provide sample image(s) that help explain this problem
I cannot provide the image, because the data is to sensitive.
The vips command line tool defaults to a "fail on" setting of "none", which is the least sensitive value. The default for sharp is "warning", which is the most sensitive value.
https://sharp.pixelplumbing.com/api-constructor
...one of (in order of sensitivity, least to most): 'none', 'truncated', 'error', 'warning'. Higher levels imply lower levels. Invalid metadata will always abort.
I hope this information helped. Please feel free to re-open with more details if further assistance is required.