UNPKG

@ngageoint/mage.image.service

Version:

Orient images attached to MAGE observations according to EXIF meta-data and generate configurable size thumbnails.

54 lines 3.2 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const adapters_images_sharp_1 = require("./adapters.images.sharp"); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const stream_1 = __importDefault(require("stream")); const imageBasePath = path_1.default.resolve(__dirname, '..', 'spec'); const destBasePath = path_1.default.resolve(__dirname, '..', 'scratch', path_1.default.basename(__filename)); void (function () { return __awaiter(this, void 0, void 0, function* () { fs_1.default.mkdirSync(destBasePath, { recursive: true }); const service = (0, adapters_images_sharp_1.SharpImageService)(); const unorientedPath = path_1.default.resolve(imageBasePath, 'majestic_ram.orient.raw-6.tag-6.jpg'); const source = { mediaType: 'image/jpeg', bytes: fs_1.default.createReadStream(unorientedPath) }; const orientedPath = path_1.default.resolve(destBasePath, 'majestic_ram.oriented.jpg'); const orientedDest = fs_1.default.createWriteStream(orientedPath); const oriented = yield service.autoOrient(source, orientedDest); if (oriented instanceof Error) { throw oriented; } console.info('oriented:', oriented); const orientedBytes = fs_1.default.readFileSync(orientedPath); for (const thumbSize of [72, 120, 256]) { const source = Object.assign(Object.assign({}, oriented), { bytes: stream_1.default.Readable.from(orientedBytes) }); const destPath = path_1.default.resolve(destBasePath, `majestic_ram@${thumbSize}.jpg`); const dest = fs_1.default.createWriteStream(destPath); yield service.scaleToDimension(thumbSize, source, dest); } const corruptedBytes = fs_1.default.readFileSync(path_1.default.join(imageBasePath, 'corrupted.jpeg')); const corruptedSource = { mediaType: 'image/jpeg', bytes: stream_1.default.Readable.from(corruptedBytes) }; const corruptedDestPath = path_1.default.join(destBasePath, 'corrupted.oriented.jpeg'); const corruptedDest = fs_1.default.createWriteStream(corruptedDestPath); yield service.autoOrient(corruptedSource, corruptedDest); }); })(); //# sourceMappingURL=adapters.images.sharp.visual.test.js.map