Skip to content

Instantly share code, notes, and snippets.

@nabettu
Created August 29, 2018 02:29
Show Gist options
  • Save nabettu/efc0a1268e0e977a50918fb4b6fe441d to your computer and use it in GitHub Desktop.
Save nabettu/efc0a1268e0e977a50918fb4b6fe441d to your computer and use it in GitHub Desktop.
image exif判定で画像くるくる
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