Created
August 29, 2018 02:29
-
-
Save nabettu/efc0a1268e0e977a50918fb4b6fe441d to your computer and use it in GitHub Desktop.
image exif判定で画像くるくる
This file contains hidden or 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
import loadImage from 'blueimp-load-image'; | |
// fileを読み込んでblobとcanvasを返す | |
export default function(file) { | |
return new Promise((resolve, reject) => { | |
if (!file.type.match('image.*')) { | |
reject('画像以外のファイルです'); | |
} | |
if (file.size > 10485760) { | |
reject('10MBまでの画像がアップロード出来ます。'); | |
console.log(file.size); | |
} | |
loadImage.parseMetaData(file, fileData => { | |
const options = { | |
maxHeight: 1024, | |
maxWidth: 1024, | |
canvas: true | |
}; | |
if (fileData.exif) { | |
options.orientation = fileData.exif.get('Orientation'); | |
} | |
loadImage(file, canvas => { | |
canvas.toBlob(blob => { | |
resolve({blob, canvas}); | |
}) | |
}, options); | |
}); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment