UNPKG

diginext-utils

Version:
39 lines 1.75 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import loadImage from "blueimp-load-image"; export const resize = (file, options) => __awaiter(void 0, void 0, void 0, function* () { 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 = yield loadImage(file, Object.assign(Object.assign({ // meta: false, canvas: true }, options), { maxWidth, maxHeight })); const blob = yield 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; //# sourceMappingURL=resize.js.map