@genexus/web-standard-functions
Version:
GeneXus JavaScript standard functions library for web generators
35 lines • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.scale = void 0;
const scale = async (image, percentage) => {
const img = new Image();
return new Promise((resolve, reject) => {
img.onload = async function () {
const canvas = document.createElement("canvas");
const context = canvas.getContext("2d");
canvas.width = img.width * (percentage / 100);
canvas.height = img.height * (percentage / 100);
context.drawImage(img, 0, 0, canvas.width, canvas.height);
const src = context.canvas.toDataURL();
try {
const response = await fetch(src);
const blob = await response.blob();
const name = image.uri.substring(image.uri.lastIndexOf("/") + 1, image.uri.length);
const file = new File([blob], name.split(".")[0] +
"_" +
canvas.width +
"x" +
canvas.height +
"." +
name.split(".")[1], { type: blob.type });
resolve(file);
}
catch (err) {
console.log(err.name, err.message);
}
};
img.src = image.uri;
});
};
exports.scale = scale;
//# sourceMappingURL=scale.js.map