magica
Version:
ImageMagick for browser and Node.js, easy setup, high level API and Command Line Interface, including WASM binary for an easy setup.
37 lines • 2.07 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const assert_1 = require("assert");
const misc_utils_of_mine_generic_1 = require("misc-utils-of-mine-generic");
const file_1 = require("../file/file");
const main_1 = require("../main/main");
/**
* Execute `convert $IMG info.json` to extract image metadata. Returns the parsed info.json file contents
* @param img could be a string in case you want to extract information of built in images like `rose:`
*/
function imageInfo(img) {
return __awaiter(this, void 0, void 0, function* () {
if (!img) {
return Promise.resolve([]);
}
var files = yield Promise.all(misc_utils_of_mine_generic_1.asArray(img).map((img) => __awaiter(this, void 0, void 0, function* () { return typeof img === 'string' ? yield file_1.File.resolve(img) : [img]; })));
const r = yield main_1.main({
inputFiles: files.flat().filter(misc_utils_of_mine_generic_1.notUndefined),
command: ['convert', ...misc_utils_of_mine_generic_1.asArray(img).map(img => typeof img === 'string' ? img : img.name), 'imgInfo.json']
});
assert_1.equal(r.outputFiles.length, 1);
const s = file_1.File.asString(r.outputFiles[0]);
const obj = JSON.parse(s);
return obj;
});
}
exports.imageInfo = imageInfo;
//# sourceMappingURL=imageInfo.js.map