UNPKG

image-classifier-ts

Version:

Command line tool to auto-classify images, renaming them with appropriate labels. Uses Node and Google Vision API.

73 lines 3.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ImageProperties = void 0; var path = require("path"); var ExifUtils_1 = require("../utils/ExifUtils"); var FileUtils_1 = require("../utils/FileUtils"); // immutable object! var ImageProperties = /** @class */ (function () { function ImageProperties(imagePath, topLabels, exif, dimensions, fileSizeMb, location) { if (topLabels === void 0) { topLabels = []; } if (exif === void 0) { exif = new ExifUtils_1.ExifTagSet(); } if (dimensions === void 0) { dimensions = null; } if (fileSizeMb === void 0) { fileSizeMb = null; } if (location === void 0) { location = null; } this.imagePath = imagePath; this.topLabels = topLabels; this.exif = exif; this.dimensions = dimensions; this.fileSizeMb = fileSizeMb; this.location = location; } ImageProperties.withFileSizeMb = function (properties, fileSizeMb) { return new ImageProperties(properties.imagePath, properties.topLabels, properties.exif, properties.dimensions, fileSizeMb, properties.location); }; ImageProperties.withLocation = function (properties, location) { return new ImageProperties(properties.imagePath, properties.topLabels, properties.exif, properties.dimensions, properties.fileSizeMb, location); }; ImageProperties.withTopLabels = function (properties, topLabels) { return new ImageProperties(properties.imagePath, topLabels, properties.exif, properties.dimensions, properties.fileSizeMb, properties.location); }; Object.defineProperty(ImageProperties.prototype, "fileSizeMbText", { get: function () { return this.addSizeSuffix(this._getFileSizeMbText()); }, enumerable: false, configurable: true }); ImageProperties.prototype._getFileSizeMbText = function () { if (this.fileSizeMb === null) { return "Unknown"; } return this.roundToFewPlaces(this.fileSizeMb).toString(); }; ImageProperties.prototype.roundToFewPlaces = function (value) { return Math.round(value * 10) / 10; }; ImageProperties.prototype.addSizeSuffix = function (value) { return value + "Mb"; }; Object.defineProperty(ImageProperties.prototype, "imageFilename", { get: function () { return path.basename(this.imagePath); }, enumerable: false, configurable: true }); ImageProperties.prototype.modificationDate = function (outputter) { return FileUtils_1.FileUtils.getModificationDateOfFile(this.imagePath, outputter); }; Object.defineProperty(ImageProperties.prototype, "topLabel", { get: function () { if (this.topLabels.length === 0) { return ""; } return this.topLabels[0]; }, enumerable: false, configurable: true }); return ImageProperties; }()); exports.ImageProperties = ImageProperties; //# sourceMappingURL=ImageProperties.js.map