UNPKG

diginext-utils

Version:
34 lines (33 loc) 1.02 kB
import loadImage from "blueimp-load-image"; export 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 loadImage(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; }; export default resize;