filmout_manager/dist/image/index.js

48 lines
1.6 KiB
JavaScript
Raw Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Image = void 0;
const sharp_1 = __importDefault(require("sharp"));
const hash_1 = require("../hash");
class Image {
constructor() {
this.thumbnailCache = null;
this.thumbnailHash = null;
this.blankCache = null;
this.blankHash = null;
}
async thumbnail(path, width, height) {
const hash = hash_1.Hashes.stringHash(`${path},${width},${height}`);
if (hash !== this.thumbnailHash) {
const options = {
width,
height,
fit: sharp_1.default.fit.fill
};
this.thumbnailCache = await (0, sharp_1.default)(path).resize(options).jpeg().toBuffer();
this.thumbnailHash = hash;
}
return this.thumbnailCache;
}
async blank(width, height) {
const hash = hash_1.Hashes.stringHash(`${width},${height}`);
if (hash !== this.blankHash) {
const options = {
create: {
width,
height,
channels: 3,
background: { r: 125, g: 125, b: 125 }
}
};
this.blankCache = await (0, sharp_1.default)(options).jpeg().toBuffer();
this.blankHash = hash;
}
return this.blankCache;
}
}
exports.Image = Image;
module.exports = { Image };
//# sourceMappingURL=index.js.map