├── .editorconfig ├── .gitattributes ├── .gitignore ├── cli.js ├── fixtures ├── test_CR2.CR2 ├── test_JPG.jpg └── test_PNG.png ├── index.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | fixtures/output/ 3 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | var meow = require('meow'); 4 | var imgc = require('./'); 5 | 6 | var cli = meow({ 7 | help: [ 8 | 'Usage', 9 | ' $ imgc --format ', 10 | ' $ imgc --format --quality ', 11 | ' $ imgc --format --out ', 12 | '', 13 | 'Example', 14 | ' $ imgc *.CR2 --format jpeg --quality high', 15 | ' $ imgc *.jpg *.png --format tiff --out ./output/tiff', 16 | '', 17 | 'Options', 18 | ' -f, --format File format of converted files', 19 | ' -o, --out Where to place the files', 20 | ' -s, --quality Quality of converted files', 21 | '', 22 | 'Formats', 23 | ' jpeg | tiff | png | gif | jp2 | pict | bmp | qtif | psd | sgi | tga', 24 | '', 25 | 'Qualities', 26 | ' low | normal | high | best | ' 27 | ] 28 | }, { 29 | string: [ 30 | 'format', 31 | 'out', 32 | 'quality' 33 | ], 34 | alias: { 35 | f: 'format', 36 | o: 'out', 37 | q: 'quality' 38 | }, 39 | default: { 40 | out: process.cwd() 41 | } 42 | }); 43 | 44 | if (!cli.flags.format) { 45 | console.error([ 46 | 'Format is required in order to convert.', 47 | '', 48 | 'Formats', 49 | ' jpeg | tiff | png | gif | jp2 | pict | bmp | qtif | psd | sgi | tga' 50 | ].join('\n')); 51 | process.exit(1); 52 | } 53 | 54 | imgc(cli.input.join(' '), cli.flags.out, {format: cli.flags.format, quality: cli.flags.quality}) 55 | .then(function () { 56 | console.log('Images was successfully converted'); 57 | }) 58 | .catch(function (err) { 59 | console.error(err.message.match(/(Error [0-9]: ).+/)[0]); 60 | process.exit(1); 61 | }); 62 | -------------------------------------------------------------------------------- /fixtures/test_CR2.CR2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gillstrom/imgc/fb26213ffbf0058fffe3ef4b39731e879e1081bc/fixtures/test_CR2.CR2 -------------------------------------------------------------------------------- /fixtures/test_JPG.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gillstrom/imgc/fb26213ffbf0058fffe3ef4b39731e879e1081bc/fixtures/test_JPG.jpg -------------------------------------------------------------------------------- /fixtures/test_PNG.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gillstrom/imgc/fb26213ffbf0058fffe3ef4b39731e879e1081bc/fixtures/test_PNG.png -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var exec = require('child_process').exec; 3 | var mkdirp = require('mkdirp'); 4 | var Promise = require('pinkie-promise'); 5 | var pify = require('pify'); 6 | var formats = [ 7 | 'jpeg', 8 | 'tiff', 9 | 'png', 10 | 'gif', 11 | 'jp2', 12 | 'pict', 13 | 'bmp', 14 | 'qtif', 15 | 'psd', 16 | 'sgi', 17 | 'tga' 18 | ]; 19 | 20 | var qualities = [ 21 | 'low', 22 | 'normal', 23 | 'high', 24 | 'best' 25 | ]; 26 | 27 | module.exports = function (files, dest, opts) { 28 | opts = opts || {}; 29 | 30 | if (process.platform !== 'darwin') { 31 | return Promise.reject(new Error('Only OS X systems are supported')); 32 | } 33 | 34 | if (typeof files !== 'string') { 35 | return Promise.reject(new TypeError('Expected a string')); 36 | } 37 | 38 | if (typeof dest !== 'string') { 39 | return Promise.reject(new TypeError('Expected a destination')); 40 | } 41 | 42 | if (!opts.format) { 43 | return Promise.reject(new Error('Format is required in order to convert')); 44 | } 45 | 46 | if (formats.indexOf(opts.format) === -1) { 47 | return Promise.reject(new Error('Format not supported')); 48 | } 49 | 50 | if (opts.quality && qualities.indexOf(opts.quality) === -1 && typeof Number(opts.quality) !== 'number') { 51 | return Promise.reject(new Error('Quality not supported')); 52 | } 53 | 54 | return pify(mkdirp, Promise)(dest).then(function () { 55 | var cmd = [ 56 | 'sips', 57 | '-s format', 58 | opts.format, 59 | opts.quality ? '-s formatOptions ' + opts.quality : '', 60 | files, 61 | '--out', 62 | dest 63 | ].join(' '); 64 | 65 | return pify(exec, Promise)(cmd); 66 | }); 67 | }; 68 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Andreas Gillström (github.com/gillstrom) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "imgc", 3 | "version": "2.0.1", 4 | "description": "An image converter for OS X systems.", 5 | "license": "MIT", 6 | "repository": "gillstrom/imgc", 7 | "author": { 8 | "email": "andreasgillstrom@gmail.com", 9 | "name": "Andreas Gillström", 10 | "url": "github.com/gillstrom" 11 | }, 12 | "bin": "cli.js", 13 | "engines": { 14 | "node": ">=0.10.0" 15 | }, 16 | "scripts": { 17 | "test": "xo && ava" 18 | }, 19 | "files": [ 20 | "cli.js", 21 | "index.js" 22 | ], 23 | "keywords": [ 24 | "CR2", 25 | "cli", 26 | "cli-app", 27 | "convert", 28 | "converter", 29 | "image", 30 | "img", 31 | "jpg", 32 | "mac", 33 | "os x", 34 | "osx", 35 | "png", 36 | "raw", 37 | "sips" 38 | ], 39 | "dependencies": { 40 | "meow": "^3.3.0", 41 | "mkdirp": "^0.5.1", 42 | "pify": "^2.2.0", 43 | "pinkie-promise": "^1.0.0" 44 | }, 45 | "devDependencies": { 46 | "ava": "^0.2.0", 47 | "xo": "*" 48 | }, 49 | "xo": { 50 | "ignores": [ 51 | "test.js" 52 | ] 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # imgc 2 | 3 | > An image converter for OS X systems. 4 | 5 | 6 | ## Install 7 | 8 | ``` 9 | $ npm install --save imgc 10 | ``` 11 | 12 | 13 | ## Usage 14 | 15 | ```js 16 | const imgc = require('imgc'); 17 | 18 | imgc('*.CR2 *.png', 'dest', {format: 'jpeg', quality: 'medium'}.then(() => { 19 | console.log('Images converted'); 20 | }); 21 | ``` 22 | 23 | 24 | ## CLI 25 | 26 | ``` 27 | $ npm install --global imgc 28 | ``` 29 | 30 | ``` 31 | $ imgc --help 32 | 33 | Usage 34 | $ imgc --format 35 | $ imgc --format --quality 36 | $ imgc --format --out 37 | 38 | Example 39 | $ imgc *.CR2 --format jpeg --quality high 40 | $ imgc *.jpg *.png --format tiff --out ./output/tiff 41 | 42 | Options 43 | -f, --format File format of converted files 44 | -o, --out Where to place the files 45 | -s, --quality Quality of converted files 46 | 47 | Formats 48 | jpeg | tiff | png | gif | jp2 | pict | bmp | qtif | psd | sgi | tga 49 | 50 | Qualities 51 | low | normal | high | best | 52 | ``` 53 | 54 | 55 | ## API 56 | 57 | ### imgc(input, dest, options) 58 | 59 | Returns a promise that resolves when images are converted. 60 | 61 | #### input 62 | 63 | *Required* 64 | Type: `string` 65 | 66 | String of file paths to images. 67 | 68 | #### dest 69 | 70 | *Required* 71 | Type: `string` 72 | 73 | Destination folder for converted images. 74 | 75 | #### options 76 | 77 | *Required* 78 | Type: `object` 79 | 80 | ##### options.format 81 | 82 | *Required* 83 | Type: `string` 84 | 85 | Set the format to convert to, e.g. `jpeg`. 86 | 87 | ##### options.quality 88 | 89 | Type: `string` 90 | 91 | Set the quality of converted images, e.g. `best`. 92 | 93 | 94 | ## License 95 | 96 | MIT © [Andreas Gillström](http://github.com/gillstrom) 97 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | import {stat} from 'fs'; 3 | import test from 'ava'; 4 | import imgc from './'; 5 | 6 | test('Should output jpeg', t => { 7 | t.plan(2); 8 | 9 | imgc('./fixtures/*.CR2 ./fixtures/*.png', './fixtures/output', {format: 'jpeg', quality: 'medium'}).then(() => { 10 | stat('./fixtures/output/test_CR2.jpg', err => { 11 | t.assert(!err, err); 12 | }); 13 | 14 | stat('./fixtures/output/test_PNG.jpg', err => { 15 | t.assert(!err, err); 16 | }); 17 | }); 18 | }); 19 | 20 | 21 | test('Should output tiff', t => { 22 | t.plan(3); 23 | 24 | imgc('./fixtures/*.*', './fixtures/output', {format: 'tiff'}).then(() => { 25 | stat('./fixtures/output/test_CR2.tiff', err => { 26 | t.assert(!err, err); 27 | }); 28 | 29 | stat('./fixtures/output/test_PNG.tiff', err => { 30 | t.assert(!err, err); 31 | }); 32 | 33 | stat('./fixtures/output/test_JPG.tiff', err => { 34 | t.assert(!err, err); 35 | }); 36 | }); 37 | }); 38 | --------------------------------------------------------------------------------