Skip to content

Commit

Permalink
#34 removes ExifReader
Browse files Browse the repository at this point in the history
  • Loading branch information
ericnograles committed Sep 25, 2022
1 parent 89c9eb1 commit e610e10
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 121 deletions.
134 changes: 127 additions & 7 deletions dist/index.js

Large diffs are not rendered by default.

35 changes: 0 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@
"build": "NODE_ENV=production webpack --mode=production",
"dev": "webpack --watch --mode=development"
},
"repository": "https://github.com/ericnograles/browser-image-resizer.git",
"dependencies": {
"exifreader": "^4.5.1"
}
"repository": "https://github.com/ericnograles/browser-image-resizer.git"
}
26 changes: 0 additions & 26 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import ExifReader from 'exifreader';
import { initializeOrGetImg } from './browser_operations';
import { scaleImage } from './scaling_operations';

Expand All @@ -23,31 +22,6 @@ export function readAndCompressImage(file, userConfig) {
}
img.onload = function() {
let scaleImageOptions = { img, config }
if (config.autoRotate) {
if (config.debug)
console.log(
'browser-image-resizer: detecting image orientation...'
);
let Orientation = {};
try {
const Result = ExifReader.load(file);
Orientation = Result.Orientation || {};
} catch (err) {
console.error('browser-image-resizer: Error getting orientation')
console.error(err)
}
if (config.debug) {
console.log(
'browser-image-resizer: image orientation from EXIF tag = ' +
Orientation
);
}
scaleImageOptions.orientation = Orientation.value
} else if (config.debug) {
console.log(
'browser-image-resizer: ignoring EXIF orientation tag because autoRotate is false...'
);
}
try {
let blob = scaleImage(scaleImageOptions);
resolve(blob)
Expand Down
49 changes: 2 additions & 47 deletions src/scaling_operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,52 +44,6 @@ function findMaxWidth(config, canvas) {
return mWidth;
}

function exifApplied(canvas, ctx, orientation, img) {
let width = canvas.width;
let styleWidth = canvas.style.width;
let height = canvas.height;
let styleHeight = canvas.style.height;
if (orientation > 4) {
canvas.width = height;
canvas.style.width = styleHeight;
canvas.height = width;
canvas.style.height = styleWidth;
}
switch (orientation) {
case 2:
ctx.translate(width, 0);
ctx.scale(-1, 1);
break;
case 3:
ctx.translate(width, height);
ctx.rotate(Math.PI);
break;
case 4:
ctx.translate(0, height);
ctx.scale(1, -1);
break;
case 5:
ctx.rotate(0.5 * Math.PI);
ctx.scale(1, -1);
break;
case 6:
ctx.rotate(0.5 * Math.PI);
ctx.translate(0, -height);
break;
case 7:
ctx.rotate(0.5 * Math.PI);
ctx.translate(width, -height);
ctx.scale(-1, 1);
break;
case 8:
ctx.rotate(-0.5 * Math.PI);
ctx.translate(-width, 0);
break;
}
ctx.drawImage(img, 0, 0);
ctx.restore();
}

function scaleCanvasWithAlgorithm(canvas, config) {
let scaledCanvas = document.createElement('canvas');

Expand Down Expand Up @@ -217,7 +171,8 @@ export function scaleImage({ img, config, orientation = 1 } = {}) {
}

// EXIF
exifApplied(canvas, ctx, orientation, img);
ctx.drawImage(img, 0, 0);
ctx.restore();

let maxWidth = findMaxWidth(config, canvas);

Expand Down
2 changes: 1 addition & 1 deletion tests/bir-react/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class App extends Component {
};

onChange = async event => {
let image = await readAndCompressImage(event.target.files[0], { mimeType: 'image/jpeg'});
let image = await readAndCompressImage(event.target.files[0], { mimeType: 'image/jpeg', debug: true });
let base64Image = await this.convertToBase64(image);
this.setState({ image: base64Image });
};
Expand Down
2 changes: 1 addition & 1 deletion tests/bir-vue/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
this.images = images
},
async readImageAndConvertToBase64(file) {
let image = await readAndCompressImage(file, { mimeType: 'image/jpeg'} );
let image = await readAndCompressImage(file, { mimeType: 'image/png', debug: true } );
let base64Image = await this.convertToBase64(image);
return base64Image
},
Expand Down

0 comments on commit e610e10

Please sign in to comment.