Created
August 29, 2018 18:49
-
-
Save prajaybasu/3bbbcf4254fe73758942ca94aa1300e8 to your computer and use it in GitHub Desktop.
Test
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
<html> | |
<head> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/exif-js/2.3.0/exif.min.js"></script> | |
<script> | |
window.onload = getExif("1535556934547.jpg"); | |
function getExif(src) { | |
var img = new Image(); | |
img.src = src; | |
img.onload = function () { | |
EXIF.getData(img, function () { | |
var orientation = EXIF.getTag(this, "Orientation"); | |
var width = img.width; | |
var height = img.height; | |
var canvas = document.createElement('canvas'); | |
canvas.width = width; | |
canvas.height = height; | |
var context = canvas.getContext("2d"); | |
if ((orientation % 2 == 0)) | |
{ | |
} | |
switch (orientation) { | |
case 1: context.transform(1, 0, 0, 1, 0, 0); break; | |
case 2: canvas.width = img.height; canvas.height = img.width; context.transform(-1, 0, 0, 1, width, 0); break; | |
case 3: context.transform(-1, 0, 0, -1, width, height); break; | |
case 4: canvas.width = img.height; canvas.height = img.width; context.transform(1, 0, 0, -1, 0, height); break; | |
case 5: context.transform(0, 1, 1, 0, 0, 0); break; | |
case 6: canvas.width = img.height; canvas.height = img.width; context.transform(0, 1, -1, 0, height, 0); break; | |
case 7: context.transform(0, -1, -1, 0, height, width); break; | |
case 8: canvas.width = img.height; canvas.height = img.width; context.transform(0, -1, 1, 0, 0, width); break; | |
} | |
context.drawImage(img, 0, 0); | |
var imageTarget = document.createElement('img'); | |
imageTarget.src = canvas.toDataURL('image/png'); | |
imageTarget.style.width = canvas.width + 'px'; | |
imageTarget.style.height = canvas.height + 'px'; | |
document.body.appendChild(imageTarget); | |
}); | |
} | |
} | |
</script> | |
</head> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment