@ -1,6 +1,6 @@
import EXIF from 'exif-js' ;
import EXIF from 'exif-js' ;
const MAX _IMAGE _ DIMENSION = 1280 ;
const MAX _IMAGE _ PIXELS = 1638400 ; // 1280x1280px
const getImageUrl = inputFile => new Promise ( ( resolve , reject ) => {
const getImageUrl = inputFile => new Promise ( ( resolve , reject ) => {
if ( window . URL && URL . createObjectURL ) {
if ( window . URL && URL . createObjectURL ) {
@ -73,18 +73,8 @@ const processImage = (img, { width, height, orientation, type = 'image/png' }) =
const resizeImage = ( img , type = 'image/png' ) => new Promise ( ( resolve , reject ) => {
const resizeImage = ( img , type = 'image/png' ) => new Promise ( ( resolve , reject ) => {
const { width , height } = img ;
const { width , height } = img ;
let newWidth , newHeight ;
const newWidth = Math . round ( Math . sqrt ( MAX _IMAGE _PIXELS * ( width / height ) ) ) ;
const newHeight = Math . round ( Math . sqrt ( MAX _IMAGE _PIXELS * ( height / width ) ) ) ;
if ( width > height ) {
newHeight = height * MAX _IMAGE _DIMENSION / width ;
newWidth = MAX _IMAGE _DIMENSION ;
} else if ( height > width ) {
newWidth = width * MAX _IMAGE _DIMENSION / height ;
newHeight = MAX _IMAGE _DIMENSION ;
} else {
newWidth = MAX _IMAGE _DIMENSION ;
newHeight = MAX _IMAGE _DIMENSION ;
}
getOrientation ( img , type )
getOrientation ( img , type )
. then ( orientation => processImage ( img , {
. then ( orientation => processImage ( img , {
@ -104,7 +94,7 @@ export default inputFile => new Promise((resolve, reject) => {
}
}
loadImage ( inputFile ) . then ( img => {
loadImage ( inputFile ) . then ( img => {
if ( img . width < MAX _IMAGE _DIMENSION && img . height < MAX _IMAGE _DIMENSION ) {
if ( img . width * img . height < MAX _IMAGE _PIXELS ) {
resolve ( inputFile ) ;
resolve ( inputFile ) ;
return ;
return ;
}
}