UNPKG

magica

Version:

ImageMagick for browser and Node.js, easy setup, high level API and Command Line Interface, including WASM binary for an easy setup.

118 lines 5.12 kB
"use strict"; 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const misc_utils_of_mine_generic_1 = require("misc-utils-of-mine-generic"); const main_1 = require("../main/main"); const imageInfo_1 = require("./imageInfo"); function getConfigureFolders() { return __awaiter(this, void 0, void 0, function* () { const result = yield main_1.main({ command: `convert -debug configure rose: info:` }); const contains = `Searching for configure file:`; const folders = result.stderr .filter(line => line.includes(contains)) .map(line => line.substring(line.indexOf(contains) + contains.length, line.length)) .map(s => s.replace(/\/\//g, '/')) .map(s => s.substring(0, s.lastIndexOf('/'))) .map(s => s.replace(/"/g, '').trim()); return folders; }); } exports.getConfigureFolders = getConfigureFolders; let listConfigure_; /** returns the output of part of the information returned in `convert -list configure`, parsed. */ function listConfigure() { return __awaiter(this, void 0, void 0, function* () { if (!listConfigure_) { const result = yield main_1.main({ command: `convert -list configure` }); const delegatesS = result.stderr.find(l => l.trim().toLowerCase().startsWith('delegates')); const delegates = delegatesS ? delegatesS.split(/\s+/).splice(1) : []; const featuresS = result.stderr.find(l => l.trim().toLowerCase().startsWith('features')); const features = featuresS ? featuresS.split(/\s+/).splice(1) : []; listConfigure_ = { delegates, features }; } return listConfigure_; }); } exports.listConfigure = listConfigure; function listFormat() { return __awaiter(this, void 0, void 0, function* () { if (!formats) { const result = yield main_1.main({ command: `convert -list format` }); var r = /^\s*([^\s]+)\s+([^\s]+)\s+(.+)$/g; formats = result.stdout.slice(2).map(s => r.exec(s)).filter(misc_utils_of_mine_generic_1.notFalsy).filter(r => r[1] !== 'See').map(r => ({ name: r[1], flags: r[2], description: r[3], })); } return formats; }); } exports.listFormat = listFormat; let formats; /** * List of image formats that are known to be supported by wasm-imagemagick both for read and write. See `spec/formatSpec.ts`. * * has some heuristic information regarding features (not) supported by wasm-imagemagick, for example, image formats */ exports.knownSupportedReadWriteImageFormats = [ 'jpg', 'png', 'psd', // 'webp',// should be working but it's not : ImageMagick/coders/webp.c 'tiff', 'xcf', 'gif', 'bmp', 'tga', 'miff', 'ico', 'dcm', 'xpm', 'pcx', 'fits', 'ppm', 'pgm', 'pfm', 'mng', 'hdr', 'dds', 'otb', 'txt', 'psb', ]; /** * List of image formats that are known to be supported by wasm-imagemagick but only for write operation. See `spec/formatSpec.ts` */ exports.knownSupportedWriteOnlyImageFormats = [ 'ps', 'pdf', 'epdf', 'svg', 'djvu', ]; /** * list of image formats that are known to be supported by wasm-imagemagick but only for read operation. See `spec/formatSpec.ts` */ exports.knownSupportedReadOnlyImageFormats = [ // 'pix', 'mat', ]; let builtInImages; const names = ['rose:', 'logo:', 'wizard:', 'granite:', 'netscape:']; /** * Gets ImageMagick built-in images like `rose:`, `logo:`, etc in the form of {@link File}s. * @param builtIn if given it will resolve with with an array contianing only that image */ function imageBuiltIn(builtIn) { return __awaiter(this, void 0, void 0, function* () { if (!builtInImages) { builtInImages = yield misc_utils_of_mine_generic_1.serial(names.map(name => () => __awaiter(this, void 0, void 0, function* () { const info = yield imageInfo_1.imageInfo(name); const { outputFiles } = yield main_1.main({ command: `convert ${name} ${`output1.${info[0].image.format.toLowerCase()}`}`, inputFiles: [] }); outputFiles[0].name = name; return outputFiles[0]; }))); } return builtIn ? builtInImages.filter(i => i.name === builtIn) : builtInImages; }); } exports.imageBuiltIn = imageBuiltIn; //# sourceMappingURL=support.js.map