├── .gitignore ├── HISTORY.md ├── package.json ├── README.md └── bin └── psdinfo /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | ## v1.0.0 - Jul 2, 2015 2 | 3 | Initial version. 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "psdinfo", 3 | "description": "Inspect Photoshop files from the command line", 4 | "version": "1.0.2", 5 | "author": "Rico Sta. Cruz ", 6 | "bin": { 7 | "psdinfo": "bin/psdinfo" 8 | }, 9 | "bugs": { 10 | "url": "https://github.com/rstacruz/psdinfo/issues" 11 | }, 12 | "dependencies": { 13 | "js-yaml": "^3.3.1", 14 | "psd": "^3.1.0", 15 | "yargs": "^3.14.0" 16 | }, 17 | "devDependencies": {}, 18 | "homepage": "https://github.com/rstacruz/psdinfo#readme", 19 | "keywords": [ 20 | "photoshop", 21 | "psd" 22 | ], 23 | "license": "MIT", 24 | "main": "index.js", 25 | "repository": { 26 | "type": "git", 27 | "url": "git+https://github.com/rstacruz/psdinfo.git" 28 | }, 29 | "scripts": { 30 | "test": "mocha" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # psdinfo 2 | 3 | > Inspect PSD files from the command line. 4 | 5 | ![](https://www.evernote.com/l/AYOnmuV6pJVANbUk4XIDCtYEUh5XH2onzJkB/image.png) 6 | 7 | ``` 8 | npm install -g psdinfo 9 | ``` 10 | 11 | ```sh 12 | $ psdinfo file.psd --fonts 13 | 14 | # file.psd 15 | fonts: 16 | - DIN-Bold 17 | - FreightSansLight 18 | - Glosa-Roman 19 | - ... 20 | ``` 21 | 22 | ```sh 23 | $ psdinfo file.psd --text 24 | 25 | # file.psd 26 | text: 27 | - "Hello" 28 | - "This is text from the document" 29 | - ... 30 | ``` 31 | 32 |
33 | 34 | ## Thanks 35 | 36 | **psdinfo** © 2015+, Rico Sta. Cruz. Released under the [MIT] License.
37 | Authored and maintained by Rico Sta. Cruz with help from contributors ([list][contributors]). 38 | 39 | > [ricostacruz.com](http://ricostacruz.com)  ·  40 | > GitHub [@rstacruz](https://github.com/rstacruz)  ·  41 | > Twitter [@rstacruz](https://twitter.com/rstacruz) 42 | 43 | [MIT]: http://mit-license.org/ 44 | [contributors]: http://github.com/rstacruz/psdinfo/contributors 45 | -------------------------------------------------------------------------------- /bin/psdinfo: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var argv = require('yargs') 3 | .option('fonts', { alias: 'f', type: 'boolean' }) 4 | .option('text', { alias: 't', type: 'boolean' }) 5 | .option('doc', { alias: 'd', type: 'boolean' }) 6 | .option('full', { alias: 'F', type: 'boolean' }) 7 | .argv 8 | 9 | var assign = require('util')._extend 10 | 11 | if (!module.parent) { 12 | if (argv._.length === 0 || argv.help || argv.h) { 13 | console.log("Usage:") 14 | console.log(" psdinfo FILE.psd [--fonts] [--text] [--doc] [--full]") 15 | process.exit(0) 16 | } 17 | 18 | run(argv._) 19 | } 20 | 21 | /* 22 | * Returns a summary of the PSD document 23 | */ 24 | 25 | function getSummary (data) { 26 | return { 27 | document: { 28 | width: data.document.width, 29 | height: data.document.height 30 | } 31 | } 32 | } 33 | 34 | /* 35 | * Returns fonts in the document 36 | */ 37 | 38 | function getFonts (data) { 39 | return { 40 | fonts: pluckOut(data, 'text', function (text) { 41 | return text && text.font && text.font.name 42 | }) 43 | } 44 | } 45 | 46 | /* 47 | * Returns texts found in the document 48 | */ 49 | 50 | function getStrings (data) { 51 | return { 52 | text: pluckOut(data, 'text', function (text) { 53 | return text && text.value 54 | }) 55 | } 56 | } 57 | 58 | function pluckOut (data, parent, fn) { 59 | var out = {} 60 | walk(data, parent, function (node) { 61 | var result = fn(node) 62 | if (result) out[result] = true 63 | }) 64 | return Object.keys(out).sort() 65 | } 66 | 67 | function walk (object, needle, fn) { 68 | for (var key in object) { 69 | if (key === needle) { 70 | fn(object[key]) 71 | } else if (typeof object[key] === 'object') { 72 | walk(object[key], needle, fn) 73 | } 74 | } 75 | } 76 | 77 | function run (files) { 78 | if (!argv.fonts && !argv.text && !argv.doc && !argv.full) { 79 | console.error('options missing; see --help') 80 | process.exit(1) 81 | } 82 | 83 | files.forEach(function (file) { 84 | require('psd').open(file) 85 | .then(function (psd) { 86 | return psd.tree().export() 87 | }) 88 | .then(function (data) { 89 | if (argv.full) return data 90 | 91 | var obj = {} 92 | if (argv.fonts) assign(obj, getFonts(data)) 93 | if (argv.text) assign(obj, getStrings(data)) 94 | if (argv.doc) assign(obj, getSummary(data)) 95 | return obj 96 | }) 97 | .then(function (data) { 98 | log(data, file) 99 | }) 100 | .catch(function (err) { 101 | console.error(err.message) 102 | process.exit(1) 103 | }) 104 | }) 105 | } 106 | 107 | /* 108 | * Logs a block of JSON data to the console 109 | */ 110 | 111 | function log (data, heading) { 112 | var repr = '' 113 | if (process.stdout.isTTY) { 114 | if (heading) repr += '\033[32m →\033[30m ' + heading + '\033[0m\n\n' 115 | repr += ' ' + require('js-yaml').dump(data).replace(/\n/g, '\n ') 116 | repr = '\n' + repr.trim() 117 | } else { 118 | repr = JSON.stringify(data, null, 2) 119 | } 120 | console.log(repr) 121 | } 122 | 123 | /* 124 | * export 125 | */ 126 | 127 | exports.getFonts = getFonts 128 | exports.getStrings = getStrings 129 | exports.getSummary = getSummary 130 | --------------------------------------------------------------------------------