Created
January 14, 2014 09:14
-
-
Save katapad/8415449 to your computer and use it in GitHub Desktop.
画像が奇数ピクセルだとスマホ表示でにじむので、偶数に変更するnodeスクリプト ref: http://qiita.com/katapad/items/261b277f1abe20018fa1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
set even pixel | |
@use | |
https://github.com/rsms/node-imagemagick | |
@see | |
画像処理についてあれこれ: ImageMagickで、画像の上下左右に余白を追加する | |
http://goo.gl/kVfP9Q | |
### | |
argv = require('optimist').argv | |
if not argv.i | |
console.log 'file not found' | |
return | |
if argv.i | |
fileList = [argv.i] | |
if argv._ | |
fileList = fileList.concat(argv._) | |
if fileList?.length == 0 | |
console.log 'file not found' | |
return | |
im = require('imagemagick') | |
evenize = (fileName)=> | |
im.identify fileName, (err, features) -> | |
throw err if err | |
direction1 = '' | |
direction2 = '' | |
south = 0 | |
east = 0 | |
if features.height % 2 == 1 | |
direction1 = 'south' | |
south = 1 | |
if features.width % 2 == 1 | |
direction2 = 'east' | |
east = 1 | |
direction = "#{direction1}#{direction2}" | |
#-background #e2ddd4 -gravity southeast -splice 1999x25 sample367e.png | |
if south or east | |
im.convert([fileName, '-background', 'rgba(0, 0, 0, 0)','-gravity', direction, '-splice', "#{east}x#{south}", fileName], (err, stdout) -> | |
throw err if err | |
console.log "complete:", fileName | |
) | |
for fileName in fileList | |
evenize(fileName) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
coffee convert.coffee -i hogehoge/*.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "setEvenPixel", | |
"version": "0.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "" | |
}, | |
"author": "katapad", | |
"license": "none", | |
"devDependencies": { | |
"imagemagick": "~0.1.3", | |
"optimist": "~0.6.0" | |
}, | |
"dependencies": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment