Created
December 7, 2014 02:09
-
-
Save spelufo/af28a2580bc60d203943 to your computer and use it in GitHub Desktop.
Swap the left and right sides of an image
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
#!/usr/bin/env node | |
var lwip = require('lwip'); | |
var path = require('path'); | |
var file = path.resolve(process.argv[2]); | |
var newfile = path.join(path.dirname(file), | |
path.basename(file, path.extname(file))+'_SWAPPED'+path.extname(file) ) | |
lwip.open(file, swaplr) | |
function swaplr (err, img) { | |
if (err) throw err; | |
var h = img.height(), w = img.width(); | |
img.extract(1, 1, w/2, h, function (err, left) { | |
if (err) throw err; | |
img.extract(w/2+1, 1, w, h, function (err, right) { | |
if (err) throw err; | |
img.paste(0, 0, right, function (err, img) { | |
if (err) throw err; | |
img.paste(img.width()/2, 0, left, function (err, img) { | |
if (err) throw err; | |
img.writeFile(newfile, function (err) { | |
if (err) throw err; | |
}) | |
}) | |
}) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment