browser-image-resizer
Advanced tools
Comparing version 2.3.3 to 2.4.0
@@ -5,3 +5,2 @@ export interface Config { | ||
maxHeight?: number | ||
autoRotate?: boolean | ||
debug?: boolean | ||
@@ -8,0 +7,0 @@ mimeType?: string |
{ | ||
"name": "browser-image-resizer", | ||
"version": "2.3.3", | ||
"version": "2.4.0", | ||
"description": "A browser-based utility to downscale and resize images using <canvas>", | ||
@@ -20,6 +20,3 @@ "main": "dist/index.js", | ||
}, | ||
"repository": "https://github.com/ericnograles/browser-image-resizer.git", | ||
"dependencies": { | ||
"exifreader": "^4.5.1" | ||
} | ||
"repository": "https://github.com/ericnograles/browser-image-resizer.git" | ||
} |
# browser-image-resizer | ||
A tiny (~7kb ) browser-based library to downscale and/or resize images using `<canvas>`. | ||
## Introduction | ||
This library allows for cross-browser image downscaling and resizing utilizing `<canvas>`. The code was part of Ross Turner's [HTML5-ImageUploader](https://github.com/rossturner/HTML5-ImageUploader). Note that this is meant to be a browser-only utility and will not work in Node.js. | ||
The code was part of Ross Turner's [HTML5-ImageUploader](https://github.com/rossturner/HTML5-ImageUploader). Note that this is meant to be a browser-only utility and will not work in Node.js. | ||
@@ -38,3 +40,2 @@ ## Demo | ||
maxHeight: 600, | ||
autoRotate: true, | ||
debug: true | ||
@@ -108,3 +109,2 @@ }; | ||
maxHeight: 600, | ||
autoRotate: true, | ||
debug: true | ||
@@ -111,0 +111,0 @@ }; |
@@ -1,2 +0,1 @@ | ||
import ExifReader from 'exifreader'; | ||
import { initializeOrGetImg } from './browser_operations'; | ||
@@ -26,27 +25,2 @@ import { scaleImage } from './scaling_operations'; | ||
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 { | ||
@@ -53,0 +27,0 @@ let blob = scaleImage(scaleImageOptions); |
@@ -47,48 +47,2 @@ import { dataURIToBlob } from './data_operations'; | ||
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) { | ||
@@ -221,3 +175,4 @@ let scaledCanvas = document.createElement('canvas'); | ||
// EXIF | ||
exifApplied(canvas, ctx, orientation, img); | ||
ctx.drawImage(img, 0, 0); | ||
ctx.restore(); | ||
@@ -224,0 +179,0 @@ let maxWidth = findMaxWidth(config, canvas); |
@@ -12,3 +12,3 @@ import React, { Component } from "react"; | ||
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); | ||
@@ -15,0 +15,0 @@ this.setState({ image: base64Image }); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
0
1
2
0
2040985
49084
- Removedexifreader@^4.5.1
- Removed@xmldom/xmldom@0.9.7(transitive)
- Removedexifreader@4.26.1(transitive)