Shoora
5/3/2019 - 4:31 AM

Find images that have been resized from their natural dimensions

Find images that have been resized from their natural dimensions

function getImageDimensions(path,callback) {
    var img = new Image();
    img.onload = function () {
        callback({
            width: img.width,
            height: img.height
        });
    };
    img.src = path;
}

function findResizedImages() {
    $('img').each(function (i, im) {
        getImageDimensions(im.src,
            function (realDim) {
                if (realDim.width !== im.clientWidth) {
                    console.log('image %o changed from %i width to %i width', im, realDim.width, im.clientWidth);
                }

                if (realDim.height !== im.clientHeight) {
                    console.log('image %o changed from %i height to %i height', im, realDim.height, im.clientHeight);
                }
            });
    });
}

findResizedImages();