Created
July 27, 2016 23:59
-
-
Save cezary/c8fa39ca5580150b4f6dab053368e528 to your computer and use it in GitHub Desktop.
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
// https://github.com/EyalAr/lwip/issues/100#issuecomment-71363633 | |
var fs = require('fs'); | |
var exif = require('exif-parser'); | |
var lwip = require('lwip'); | |
// path is the path to your image | |
fs.readFile(path, function (err, data) { | |
if (err) throw err; | |
var exifData = false; | |
// ext is the extension of the image | |
if(ext == "jpg"){ | |
exifData = exif.create(data).parse(); | |
} | |
lwip.open(data, ext, function(err, image){ | |
if(err) throw err; | |
if(exifData){ | |
switch( exifData.tags.Orientation ) { | |
case 2: | |
image = image.batch().flip('x'); // top-right - flip horizontal | |
break; | |
case 3: | |
image = image.batch().rotate(180); // bottom-right - rotate 180 | |
break; | |
case 4: | |
image = image.batch().flip('y'); // bottom-left - flip vertically | |
break; | |
case 5: | |
image = image.batch().rotate(90).flip('x'); // left-top - rotate 90 and flip horizontal | |
break; | |
case 6: | |
image = image.batch().rotate(90); // right-top - rotate 90 | |
break; | |
case 7: | |
image = image.batch().rotate(270).flip('x'); // right-bottom - rotate 270 and flip horizontal | |
break; | |
case 8: | |
image = image.batch().rotate(270); // left-bottom - rotate 270 | |
break; | |
} | |
}else{ | |
image = image.batch(); | |
} | |
// image can now be used as per normal with batch | |
// eg. image.resize(200, 200).... | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment