diginext-utils
Version:
README.md
46 lines • 2.08 kB
JavaScript
;
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());
});
};
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 = (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 (0, blueimp_load_image_1.default)(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;
});
exports.resize = resize;
exports.default = exports.resize;
//# sourceMappingURL=resize.js.map