Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better performance (especially on large files). #9

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8ac2b37
Document im-metadata to README.md
Apr 22, 2015
a4c6f45
Tag release v1.0.3
Apr 22, 2015
f66daa7
Move test image to assets directory
Apr 26, 2015
c4a01f5
Rename `src` to `path`
Apr 26, 2015
744e2da
Return image `path` in metadata object
Apr 26, 2015
d0359fc
Tag release v1.1.0
Apr 26, 2015
57c414a
Update wercker post build Slack hook
May 2, 2015
4b8d187
Remove obsolete polling.js script
Jun 5, 2015
f715aad
Merge branch 'docker-compose'
Jun 5, 2015
f2b9a15
Parse exif metadata to a seperate object
Jun 5, 2015
092f5b2
Return exif metadata in README example
Jun 5, 2015
650436e
Merge branch 'exif-metadata-object'
Jun 5, 2015
b4f52d6
Tag release v2.0.0
Jun 5, 2015
c26ce18
Return "" for Undefiend image orientation
Jun 11, 2015
dabdbb1
Merge branch 'parse-undefied-orientation'
Jun 11, 2015
74ec9db
Tag release v2.1.0
Jun 11, 2015
f0525a6
Fix Undefiend to be Undefined
Jun 11, 2015
559a315
Tag release v2.1.1
Jun 11, 2015
3eee3a3
Add support for image auto orient
Jun 25, 2015
8a69f3d
Document auto-orient option
Jun 25, 2015
c33a0fb
Merge branch 'auto-orient'
Jun 25, 2015
d733a37
Install JSHint as a dev dependency
Jun 25, 2015
33a96d9
Set dev dependencies to latest major version
Jun 25, 2015
00cd5bd
Use Docker stack for wercker ci build and deploy
Jun 25, 2015
7c5f406
Fix spelling mistake in test.js
Jun 25, 2015
42d913a
Remove outcommented CI test for image orientation
Jun 25, 2015
db512b0
Merge branch 'wercker-docker-stack'
Jun 25, 2015
5fed310
Tag release v2.2.0
Jun 25, 2015
58e7eb7
Use ImageMagick v6.8 for Wercker CI builds
Jun 25, 2015
dd9df81
Add module requirements to README
Jun 25, 2015
2063d0e
Add Node.JS and io.js engines versions
Jun 25, 2015
b127ddc
Merge branch 'wercker-imagemagick-6-8'
Jun 25, 2015
189ef45
Tag release v2.2.1
Jun 25, 2015
36362ff
Remove image name property from identify format
Jul 28, 2015
b222899
Use iojs-imagemagick:2-6 image for dev and test
Jul 28, 2015
6cc53c5
Merge branch 'unknown-image-property-name'
Jul 28, 2015
800a4b8
Tag release v2.2.2
Jul 28, 2015
ea936ca
Safely output ImageMagick version information
Jul 28, 2015
c2faa55
fix: Return image size in bytes
anthonyringoet Oct 17, 2015
c797def
Merge pull request #2 from anthonyringoet/size-bytes
Starefossen Oct 27, 2015
88a7db7
chore(release): v3.0.0
anthonyringoet Oct 27, 2015
1867a22
chore(package): update dependencies
greenkeeperio-bot Aug 23, 2016
5301980
Merge pull request #3 from Turistforeningen/greenkeeper-update-all
Starefossen Aug 23, 2016
1fff3ea
fix(npm): ignore assets dir
llafuente Dec 22, 2016
a98c396
Merge pull request #8 from llafuente/master
Starefossen Dec 26, 2016
f007645
chore(release): v3.0.1
Dec 26, 2016
dd5f7c9
use convert -ping to efficiently get image data
aeh Mar 26, 2018
be56f13
force a higher precision for better file sizes
aeh Mar 26, 2018
495dd45
remove broken build badge
aeh Jun 23, 2021
9ec7c5e
adding github actions
jacobthesumurai Jul 6, 2021
821c8fd
Merge pull request #1 from noblesamurai/github-actions
jacobthesumurai Jul 6, 2021
51a9b84
Add tartufo pre-commit hook
watermelonpizza Jul 12, 2021
b888c6f
Merge pull request #2 from noblesamurai/tartufo-pre-commit-hook
watermelonpizza Jul 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/tartufo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 🍨 Tartufo 🏴‍☠️

on: [push]

jobs:
tartufo:
name: Run Tartufo
runs-on: ubuntu-latest
steps:
- uses: "actions/checkout@v2"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Python 🐍
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Check for leaks 💦
run: |
git pull --unshallow
pip install tartufo
tartufo --config tartufo.toml scan-local-repo .
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 🧪 Lint, Test & Check Coverage 🧐

on: [push]

jobs:
build:
name: Test the build
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12, 14]

steps:
- uses: "actions/checkout@v2"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Setup NodeJS ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install packages
run: npm install
- name: Lint & Test
run: npm run test
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/assets/
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/godaddy/tartufo
rev: v2.6.0
hooks:
- id: tartufo
79 changes: 77 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,77 @@
# node-im-metadata
Retrieve image metadata using ImageMagick's identify command
# im-metadata

[![NPM downloads](https://img.shields.io/npm/dm/im-metadata.svg "NPM downloads")](https://www.npmjs.com/package/im-metadata)
[![NPM version](https://img.shields.io/npm/v/im-metadata.svg "NPM version")](https://www.npmjs.com/package/im-metadata)
[![Node version](https://img.shields.io/node/v/im-metadata.svg "Node version")](https://www.npmjs.com/package/im-metadata)
[![Dependency status](https://img.shields.io/david/turistforeningen/node-im-metadata.svg "Dependency status")](https://david-dm.org/turistforeningen/node-im-metadata)

Retrieve image metadata as a JSON object using ImageMagick's `identify` command.

## Requiremets

* Node.JS v0.10 or newer
* ImageMagick v6.8 or newer

## Install

```
npm install im-metadata --save
```

## API

```js
var metadata = require('im-metadata');
```

### metadata(**string** `src`, **object** `opts`, **function** `callback`)

Return metadata **object** for a given `src` image.

* **string** `src` - path to the image on disk
* **object** `opts` - metadata parsing options
* **boolean** `exif` - return exif data or not (default `false`)
* **boolean** `autoOrient` - auto-orient height/width (default `false`)
* **integer** `timeout` - command timeout length (default `5000`)
* **function** `callback` - callback function (**Error** `error`, **object** `data`)
* **Error** `error` - error output if command failed
* **object** `data` - parsed metadata object

#### Return

Returns an `object` with parsed metada:

* **string** `path` - original image path
* **string** `name` - original image name
* **string** `size` - image file size in bytes (ex. `4504682`)
* **string** `format` - image format (`JPEG`, `PNG`, `TIFF` etc.)
* **string** `colorspace` - image colorspace (`RGB`, `CMYK` etc.)
* **integer** `height` - image pixel height
* **integer** `width` - image pixel width
* **string** `orientation` - image orientation

#### Example

```js
metadata('/path/to/image.jpg', {exif: true}, function(error, metadata) {
if (error) { console.error(error); }
console.log(metadata);
console.log(metadata.exif);
});
```

## Contributing

### Prerequisites

```
$ pip install pre-commit
```

### Installation

```
$ pre-commit install --install-hooks
```

## [MIT License](https://github.com/Turistforeningen/node-im-metadata/blob/master/LICENSE)
File renamed without changes
Binary file added assets/orient.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
builder:
image: starefossen/iojs-imagemagick:1.6-6.9
dev:
image: starefossen/iojs-imagemagick:2-6
working_dir: /usr/src/app
volumes:
- ".:/usr/src/app"
command: "node polling.js"
command: "npm run watch"
60 changes: 48 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
/*jshint laxbreak:true */

var sizeParser = require('filesize-parser');
var exec = require('child_process').exec, child;

module.exports = function(src, opts, cb) {
module.exports = function(path, opts, cb) {
if (!cb) {
cb = opts;
opts = {};
}

var cmd = module.exports.cmd(src, opts);
var cmd = module.exports.cmd(path, opts);
opts.timeout = opts.timeout || 5000;

exec(cmd, opts, function(e, stdout, stderr) {
if (e) { return cb(e); }
if (stderr) { return cb(new Error(stderr)); }

return cb(null, module.exports.parse(stdout));
return cb(null, module.exports.parse(path, stdout, opts));
});
};

module.exports.cmd = function(src, opts) {
module.exports.cmd = function(path, opts) {
opts = opts || {};
var format = [
'name=%[name]',
'size=%[size]',
'name=',
'size=%b',
'format=%m',
'colorspace=%[colorspace]',
'height=%[height]',
Expand All @@ -30,29 +33,62 @@ module.exports.cmd = function(src, opts) {
(opts.exif ? '%[exif:*]' : '')
].join("\n");

return 'identify -format "' + format + '" ' + src;
return 'convert -ping ' + path + ' -format "' + format + '" -precision 12 info:';
};

module.exports.parse = function(metadata) {
var lines = metadata.split('\n'), ret = {}, i;
module.exports.parse = function(path, stdout, opts) {
var lines = stdout.split('\n');
var ret = {path: path};
var i;

for (i = 0; i < lines.length; i++) {
if (lines[i]) {
lines[i] = lines[i].split('=');
ret[lines[i][0]] = lines[i][1];

// Parse exif metadata keys
if (lines[i][0].substr(0, 5) === 'exif:') {
if (!ret.exif) {
ret.exif = {};
}

ret.exif[lines[i][0].substr(5)] = lines[i][1];

// Parse normal metadata keys
} else {
ret[lines[i][0]] = lines[i][1];
}
}
}

if (ret.width) { ret.width = parseInt(ret.width, 10); }
if (ret.height) { ret.height = parseInt(ret.height, 10); }

if (ret.size && ret.size.substr(ret.size.length - 2) === "BB") {
ret.size = ret.size.substr(0, ret.size.length - 1);
if (ret.size) {
if (ret.size.substr(ret.size.length - 2) === 'BB') {
ret.size = ret.size.substr(0, ret.size.length - 1);
}

ret.size = parseInt(sizeParser(ret.size));
}

if (ret.colorspace && ret.colorspace === 'sRGB') {
ret.colorspace = 'RGB';
}

if (ret.orientation === 'Undefined') {
ret.orientation = '';
}

if (opts && opts.autoOrient
&& ( ret.orientation === 'LeftTop'
|| ret.orientation === 'RightTop'
|| ret.orientation === 'LeftBottom'
|| ret.orientation === 'RightBottom')) {

ret.width = ret.width + ret.height;
ret.height = ret.width - ret.height;
ret.width = ret.width - ret.height;
}

return ret;
};
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "im-metadata",
"version": "1.0.2",
"version": "3.0.1",
"description": "Retrieve image metadata using ImageMagick's identify command",
"main": "index.js",
"scripts": {
"test": "mocha test.js"
"test": "mocha test.js",
"hint": "./node_modules/.bin/jshint index.js test.js",
"watch": "./node_modules/.bin/mocha -w test.js"
},
"repository": {
"type": "git",
Expand All @@ -24,6 +26,14 @@
},
"homepage": "https://github.com/Turistforeningen/node-im-metadata",
"devDependencies": {
"mocha": "^2.2.4"
"jshint": "~2",
"mocha": "~3.0.2"
},
"engines": {
"node": ">=0.10",
"iojs": ">=1.0.0"
},
"dependencies": {
"filesize-parser": "^1.3.0"
}
}
30 changes: 0 additions & 30 deletions polling.js

This file was deleted.

6 changes: 6 additions & 0 deletions tartufo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[tool.tartufo]
exclude-path-patterns = [
'package-lock.json',
'tartufo.toml'
]
exclude-signatures = []
Loading