Sharp: input/output image quality

Created on 11 Aug 2017  路  6Comments  路  Source: lovell/sharp

Is it possible to know (or detect) input image quality in order to save the image with the same quality ?

question

Most helpful comment

All 6 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vermin1337 picture vermin1337  路  3Comments

Andresmag picture Andresmag  路  3Comments

emmtte picture emmtte  路  3Comments

AVVS picture AVVS  路  3Comments

genifycom picture genifycom  路  3Comments