UNPKG

diginext-utils

Version:
41 lines (40 loc) 1.36 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.resize = void 0; const blueimp_load_image_1 = __importDefault(require("blueimp-load-image")); const resize = async (file, options) => { if (!file) { console.error("NO FILE AVAIABLE!"); return; } const maxWidth = (options === null || options === void 0 ? void 0 : options.maxWidth) || 2048; const maxHeight = (options === null || options === void 0 ? void 0 : options.maxHeight) || 2048; const { type } = file; const data = await (0, blueimp_load_image_1.default)(file, { // meta: false, canvas: true, ...options, maxWidth, maxHeight, }); const blob = await new Promise(function (resolve) { try { const canvas = data.image; canvas.toBlob(function (blob) { resolve(blob); }, type); } catch (error) { console.error(`diginext-utils/src/images/resize.ts canvas.toBlob error`, error); } }); if (blob) return blob; return data; }; exports.resize = resize; exports.default = exports.resize;