Options
All
  • Public
  • Public/Protected
  • All
Menu

:camera: image-classifier-ts readme

Command line tool to auto-classify images, renaming them with appropriate address and labels. Uses Node.js and the Google Geocoding and Vision APIs.

status - stable

image-classifier-ts is stable, with ongoing development (tested on Windows, Ubuntu Linux) following semantic versioning.

Travis node

Greenkeeper badge Dependencies Dev Dependencies

npm Package NPM Downloads

styled with prettier semantic-release

License: MIT Donate

why?

The project was started as a way to avoid depending on particular photo software such as Picasa, and also to save time spent on sorting tons of photos!

dependencies

  • Node 8.11.3 or higher

dependendcies for Windows

We use sharp to resize images during processing. sharp requires node-gyp to build, so you will need to install Microsoft's windows-build-tools using this command:_

npm install --global --production windows-build-tools

features

  • process multiple image files and move them to a configurable folder, using a flexible filename template
  • auto classify the image using the Google Vision API
  • determine geographic location (address) of an image using the Google Geocoding API
  • the output filename can include date, dimensions, file size as well as labels and adress provided by Google
  • can take geographic locations from mobile photos and apply them to photos taken with a non-GPS device (matching by closest time for that date)
  • supports JPEG, PNG file formats

usage - as cli (command line tool)

1 Install dependencies

Install:

  • Yarn
  • Node 8.3.11 (or higher)

2 Configure your Google API key

see configure Google APIs.

3 Classify (label) your images

note: the processed images will be moved to the output directory. so you may want to point 'input directory' to a *copy of your images directory.*

3 ways to run

You can run image-classifier-ts in one of three ways:

  • a) as a globally installed command line tool (this is the easiest way)
  • OR b) as an npm package inside an npm project
  • OR c) from the source code
a) install globally as a command line tool

npm i -g image-classifier-ts@latest --production

on Ubuntu, you may need administrator permissions via sudo:

sudo npm i -g image-classifier-ts@latest --production

To use:

image-classifier-ts <path to image directory> <path to output directory> [-filenameFormat=<file name format>]

OR b) from the npm package

Install inside your npm project:

yarn add image-classifier-ts

via bash script:

node_modules/image-classifier-ts/dist/lib/cli.js <input directory> <output directory>

OR via node:

node node_modules/image-classifier-ts/dist/lib/main <input directory> <output directory>

OR c) from the source code
yarn

On Windows: use a bash shell like git bash.

To test your installation:

./test.sh

To classify your images:

./go.sh <path to image directory> <path to output directory> [-filenameFormat=<file name format>]

example:

./go.sh ../myPhotos ../myPhotos-labelled

To have a 'dry run' where the images are not actually moved, use the 'dryRun' option:

./go.sh ../myPhotos ../myPhotos-labelled -dryRun

To see more detailed usage info:

./go.sh
example:
./go.sh ../my-photos -filenameFormat={year}/{location}/{topLabel}/{combinedLabels}-{fileSizeMb}-{width}x{height}--{filename}
advanced - specifying locations by date

You can specify locations for the photos, by date.

Do this by adding a file named mapDateToLocation.csv in the same folder as your images.

The approprite location description will be used when renaming the image files.

For an example, see mapDateToLocation.csv

note: if the location is unknown, and the filename format includes {location}, then the image will NOT be moved.

usage - as a library in a node based project

Install inside your npm project:

yarn add image-classifier-ts

Then in TypeScript, you can import the library:

import * as ic from "image-classifier-ts";

For a working example, see the library test harness.

sites

site URL
source code (github) https://github.com/mrseanryan/image-classifier-ts
github page https://mrseanryan.github.io/image-classifier-ts/
npm https://www.npmjs.com/package/image-classifier-ts

developing code in this repository

see the contributing readme.

origin

This project is based on the excellent seeder project typescript-library-starter.

libaries

image-classifier-ts uses the ExifReader library.

ORIGINAL readme (from the seeder project)

see here

authors

Original work by Sean Ryan - mr.sean.ryan(at gmail.com)

licence = MIT

This project is licensed under the MIT License - see the LICENSE file for details

Index

Type aliases

Args

Args: object

Type declaration

  • imageInputDir: string
  • imageOutputDir: string
  • options: Options

ClassifyImageResult

ClassifyImageResult: object

Type declaration

DateAndLocation

DateAndLocation: object

Type declaration

Dimensions

Dimensions: object

Type declaration

  • height: number
  • width: number

FileNameTokens

FileNameTokens: Map<FileFormatToken, string>

ImagePropertiesAndResultsByPhase

ImagePropertiesAndResultsByPhase: object

Type declaration

LocationNameTokens

LocationNameTokens: Map<LocationFormatToken, string>

Options

Options: object

Type declaration

  • derivedLocationFormat: string
  • dryRun: boolean
  • filenameFormat: string
  • geoCode: boolean
  • locationFormat: string
  • minScore: number
  • replaceOnMove: boolean
  • topNLabels: number
  • verbosity: Verbosity

ProcessResultForPhase

ProcessResultForPhase: object

Type declaration

ResultsByPhase

ResultsByPhase: Map<Phase, ProcessResultForPhase>

Variables

Const API_KEY_ENV_VAR

API_KEY_ENV_VAR: "IMAGE_CLASSIFIER_TS_API_KEY" = "IMAGE_CLASSIFIER_TS_API_KEY"

Const AUTO_DATE_MAP_CSV_FILENAME

AUTO_DATE_MAP_CSV_FILENAME: "mapDateToLocation.auto.csv" = "mapDateToLocation.auto.csv"

Const DATE_MAP_CSV_FILENAME

DATE_MAP_CSV_FILENAME: "mapDateToLocation.csv" = "mapDateToLocation.csv"

Const DELAY_BETWEEN_API_REQUESTS_IN_MILLIS

DELAY_BETWEEN_API_REQUESTS_IN_MILLIS: number = 1000 / 20

Const DUMP_INDENT

DUMP_INDENT: " " = " "

Const ENDLINE

ENDLINE: "" = ""

Const GOOGLE_CRED_LOCATION_ENV_VAR

GOOGLE_CRED_LOCATION_ENV_VAR: "GOOGLE_APPLICATION_CREDENTIALS" = "GOOGLE_APPLICATION_CREDENTIALS"

Const KNOWN_LATITUDE_FORMAT

KNOWN_LATITUDE_FORMAT: "North latitude" = "North latitude"

Const KNOWN_LONGITUDE_FORMAT

KNOWN_LONGITUDE_FORMAT: "East longitude" = "East longitude"

Const NUM_MANDATORY_ARGS

NUM_MANDATORY_ARGS: 4 = 4

Const args

args: null | object = ArgsParser.getArgs()

Const exifReader

exifReader: any = require("exifreader")

Let hasError

hasError: boolean = false

Const outputter

outputter: IOutputter = OutputterFactory.create(args!.options.verbosity)

Const renamePromise

renamePromise: __promisify__ = promisify(fs.rename)

Const sharp

sharp: any = require("sharp")

Const sizeOf

sizeOf: any = require("image-size")

Const vision

vision: any = require("@google-cloud/vision")

Const visionClient

visionClient: any = new vision.ImageAnnotatorClient()

Functions

doClassifyPhaseForImage

doGeoCodePhaseForImage

dumpResults

Const finish

  • finish(fileCount: number, outputter: IOutputter): void

getAllImageProperties

getDelayForPhase

  • getDelayForPhase(phase: Phase): number

Const handleError

  • handleError(err: any, outputter: IOutputter): void

Const isDirectory

  • isDirectory(filepath: string): boolean

Const isFileExtensionOk

  • isFileExtensionOk(filepath: string): boolean

logThisPhase

processImageDirectory

processImagesForPhase

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc