Skip to content

Commit 09cd44b

Browse files
author
Kent C. Dodds
committed
Initial commit
0 parents  commit 09cd44b

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

index.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
var inputImagePath = process.argv[2]
2+
var Imagina = require('imagina')
3+
var path = require('path')
4+
var dir = path.dirname(inputImagePath)
5+
var extension = path.extname(inputImagePath).substring(1)
6+
var filename = path.basename(inputImagePath, '.' + extension)
7+
var resizedImagePath = path.join(dir, filename + '.resized.' + extension)
8+
9+
var im = new Imagina()
10+
11+
resize(function onResizeDone(err) {
12+
if (err) {
13+
throw err
14+
}
15+
console.log('resize done')
16+
if (extension !== 'png') {
17+
convert(resizedImagePath, function onConvertDone(err) {
18+
if (err) {
19+
throw err
20+
}
21+
console.log('Conversion done')
22+
})
23+
} else {
24+
console.log('no conversion necessary');
25+
}
26+
})
27+
28+
29+
30+
31+
function convert(inputPath, cb) {
32+
var dir = path.dirname(inputPath)
33+
var extension = path.extname(inputPath).substring(1)
34+
var filename = path.basename(inputPath, '.' + extension)
35+
var outputPath = path.join(dir, filename + '.png')
36+
console.log('converting', inputPath, outputPath)
37+
im.convert(inputPath, outputPath, cb)
38+
}
39+
40+
function resize(cb) {
41+
var params = '-resize 180x180^ -gravity center -extent 180x180'.split(' ')
42+
console.log('resizing', inputImagePath, resizedImagePath)
43+
im.resize(inputImagePath, resizedImagePath, '180x180', params, cb)
44+
}
45+
46+
function getFilename(filepath) {
47+
return filepath.split(/(\\|\/)/g).pop()
48+
}
49+

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "images",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"dependencies": {},
7+
"devDependencies": {
8+
"imagina": "0.1.4"
9+
},
10+
"scripts": {
11+
"test": "echo \"Error: no test specified\" && exit 1"
12+
},
13+
"keywords": [],
14+
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
15+
"license": "MIT"
16+
}

0 commit comments

Comments
 (0)