util-helpers
Version:
31 lines (27 loc) • 936 B
JavaScript
;
var ut2 = require('ut2');
var divide = require('./divide.js');
var gcd = require('./gcd.js');
var loadImageWithBlob = require('./loadImageWithBlob.js');
var bytesToSize = require('./bytesToSize.js');
function calcContrast(w, h) {
var n = gcd(w, h);
return "".concat(divide(ut2.round(w), n), ":").concat(divide(ut2.round(h), n));
}
function getImageInfo(img, ajaxOptions) {
return loadImageWithBlob(img, ajaxOptions).then(function (_a) {
var image = _a.image, blob = _a.blob;
var width = image.width, height = image.height;
return {
width: width,
height: height,
contrast: calcContrast(width, height),
measure: "".concat(width, " \u00D7 ").concat(height, " px"),
size: bytesToSize(blob.size),
bytes: blob.size,
image: image,
blob: blob
};
});
}
module.exports = getImageInfo;