Is it possible to know (or detect) input image quality in order to save the image with the same quality ?
Hello, I'm assuming you're referring to JPEG images. These do not contain the "quality" at which they were created.
ImageMagick attempts to reverse engineer a value, but makes assumptions about the quantisation tables so is not always correct.
Thanks for the answer.
Do you think it is possible to convert my question into a feature request, even if the result will be approximative ?
Perhaps ask over at the libvips repo to see if there's any interest, as it is through libvips that sharp interfaces with libjpeg. Alternatively you could re-implement the logic from ImageMagick separately. However your best bet is to invoke the ImageMagick logic at the command line:
identify -format '%Q' input.jpg
And for the ImageMagick command line front - if you're looking to do this in script then take a look at:
const spawn = require('child-process-promise').spawn
then invoke like:
return spawn('identify', ['-format', '"%Q"', 'input.jpg'])
The above code might not work out of the box since I've only used spawn for convert calls in the past but the general use is to pass the parameters as an array so ought to work (:fingers-crossed)
This way you'll be able to access the return of the identify in the rest of your script.
Hope this helps!
Thanks for your help,
In order to avoid ImageMagick dependency, I will try to mix https://github.com/eugeneware/jpeg-js/blob/master/lib/decoder.js and https://github.com/ImageMagick/ImageMagick/blob/master/coders/jpeg.c#L817
Most helpful comment
FYI, https://gist.github.com/FranckFreiburger/d8e7445245221c5cf38e69a88f22eeeb