Skip to content

Latest commit

 

History

History
63 lines (38 loc) · 1.82 KB

File metadata and controls

63 lines (38 loc) · 1.82 KB

JpegQuality

Extract JPEG Quality Information from the Jpeg File. Also provides image progressive status.

How it works

Jpeg quality is not stored on Meta Data. To extract the quality infomration,

  • Extract Jpeg Quantization Tables from Jpeg File Binary.
  • Approximate Quality Information from the Quantization Tables
    • Neal Krawetz Method : "For JPEG Quality > 50"
    • ImageMagic Method : "For Any JPEG Quality"

Usage

/* By Image Element */
 var image = document.getElementById("img1");

 JpegQuality.calculate(image, function(data){
       console.log(data);  /* { qualityNK : { quality : 90.00, type : 'approximate' }, qualityIM : { quality : 92.00, type : 'exact' }, progressive : false } */
 });

/* By Input Files */

   /* <input type="file" id="file" value="select a file" /> */

   var fileInput = document.getElementById('file');
   fileInput.onchange = function(){
       JpegQuality.calculate(fileInput.files[0], function(data){
           console.log(data); /* { qualityNK : { quality : 90.00, type : 'approximate' }, qualityIM : { quality : 92.00, type : 'exact' }, progressive : false } */
       });

   };


/* By Blob File */

   JpegQuality.calculate(blobFile, function(data){
       console.log(data); /* { qualityNK : { quality : 90.00, type : 'approximate' }, qualityIM : { quality : 92.00, type : 'exact' }, progressive : false } */
   });

References

http://fotoforensics.com/tutorial-estq.php

http://www.hackerfactor.com/src/jpegquality.c https://github.com/brunobar79/J-I-C https://github.com/trevor/ImageMagick/blob/master/trunk/coders/jpeg.c

https://github.com/sindresorhus/is-progressive