34 lines
4.6 KiB
JavaScript
34 lines
4.6 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const path_1 = __importDefault(require("path"));
|
|
const ensure_directory_1 = __importDefault(require("../utils/ensure-directory"));
|
|
const exec_1 = require("../utils/exec");
|
|
const binaries_1 = __importDefault(require("../binaries"));
|
|
const DEFAULT_THUMBNAIL_WIDTH = 240;
|
|
const DEFAULT_THUMBNAIL_HEIGHT = 130;
|
|
function getThumbnailPath(imagePath) {
|
|
var imageName = path_1.default.basename(imagePath);
|
|
var imageDir = path_1.default.dirname(imagePath);
|
|
return path_1.default.join(imageDir, 'thumbnails', imageName);
|
|
}
|
|
/**
|
|
* Creates a thumbnail image from the specified PNG image file.
|
|
* @function
|
|
* @async
|
|
* @name generateThumbnail
|
|
* @param {string} sourcePath - Specifies the path to the source image in PNG format.
|
|
* @param {string} thumbnailPath - Specifies the path to the resulting thumbnail image.
|
|
* Defaults to '<sourcePathDirectory>/thumbnails/<sourcePathFileName>'
|
|
* @param {number} width - Specifies the width of the thumbnail image, in pixels (default is 240).
|
|
* @param {number} height - Specifies the height of the thumbnail image, in pixels (default is 130).
|
|
*/
|
|
async function default_1(sourcePath, thumbnailPath = getThumbnailPath(sourcePath), width = DEFAULT_THUMBNAIL_WIDTH, height = DEFAULT_THUMBNAIL_HEIGHT) {
|
|
if (!await ensure_directory_1.default(thumbnailPath))
|
|
return;
|
|
await exec_1.execFile(binaries_1.default.generateThumbnail, [sourcePath, thumbnailPath, width, height]);
|
|
}
|
|
exports.default = default_1;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXJhdGUtdGh1bWJuYWlsLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2FwaS9nZW5lcmF0ZS10aHVtY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