![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
browser-image-resizer
Advanced tools
A browser-based utility to downscale and resize images using <canvas>
A tiny (~7kb uncompressed, ~1kb compressed) browser-based library to downscale and/or resize images using <canvas>
.
The code was part of Ross Turner's HTML5-ImageUploader. Note that this is meant to be a browser-only utility and will not work in Node.js.
npm install browser-image-resizer
yarn add browser-image-resizer
<script src="https://cdn.jsdelivr.net/gh/ericnograles/browser-image-resizer@2.4.0/dist/index.js"></script>
import { readAndCompressImage } from 'browser-image-resizer';
const config = {
quality: 0.5,
maxWidth: 800,
maxHeight: 600,
debug: true
};
// Note: A single file comes from event.target.files on <input>
readAndCompressImage(file, config)
.then(resizedImage => {
// Upload file to some Web API
const url = `http://localhost:3001/upload`;
const formData = new FormData();
formData.append('images', resizedImage);
const options = {
method: 'POST',
body: formData
};
return fetch(url, options);
})
.then(result => {
// TODO: Handle the result
console.log(result);
});
import { readAndCompressImage } from 'browser-image-resizer';
const config = {
quality: 0.7,
width: 800,
height: 600
};
// Note: A single file comes from event.target.files on <input>
async function uploadImage(file) {
try {
let resizedImage = await readAndCompressImage(file, config);
const url = `http://localhost:3001/upload`;
const formData = new FormData();
formData.append('images', resizedImage);
const options = {
method: 'POST',
body: formData
};
let result = await fetch(url, options);
// TODO: Handle the result
console.log(result);
return result;
} catch (error) {
console.error(error);
throw(error);
}
}
const config = {
quality: 0.5,
maxWidth: 800,
maxHeight: 600,
debug: true
};
// Note: A single file comes from event.target.files on <input>
BrowserImageResizer.readAndCompressImage(file, config)
.then(resizedImage => {
// Upload file to some Web API
const url = `http://localhost:3001/upload`;
const formData = new FormData();
formData.append('images', resizedImage);
const options = {
method: 'POST',
body: formData
};
return fetch(url, options);
})
.then(result => {
// TODO: Handle the result
console.log(result);
});
const config = {
quality: 0.7,
width: 800,
height: 600
};
// Note: A single file comes from event.target.files on <input>
async function uploadImage(file) {
try {
let resizedImage = await BrowserImageResizer.readAndCompressImage(file, config);
const url = `http://localhost:3001/upload`;
const formData = new FormData();
formData.append('images', resizedImage);
const options = {
method: 'POST',
body: formData
};
let result = await fetch(url, options);
// TODO: Handle the result
console.log(result);
return result;
} catch (error) {
console.error(error);
throw(error);
}
}
file
: A File object, usually from an <input>
config
: See belowProperty Name | Purpose | Default Value |
---|---|---|
quality | The quality of the image | 0.5 |
maxWidth | The maximum width for the downscaled image | 800 |
maxHeight | The maximum height for the downscaled image | 600 |
autoRotate | Reads EXIF data on the image to determine orientation | true |
debug | console.log image update operations | false |
mimeType | specify image output type other than jpeg | 'image/jpeg' |
A Promise that yields an Image Blob
The fastest way to contribute back is to fork the repl.it of this repo (https://replit.com/@grales/browser-image-resizer). Please open any Issues if you have trouble spinning it up.
Upon forking of the repl.it, open a new Shell and follow these instructions:
npm link
at the top ~/browser-image-resizer
foldercd tests/bir-vue
npm i && npm link browser-image-resizer && npm run serve
src/
and it will reflect on your Vue 3 CLI SPA test appdev
script of the library, which is a webpack-dev-server that auto-generates the dist/
library which is the entry point of this libraryFAQs
A browser-based utility to downscale and resize images using <canvas>
The npm package browser-image-resizer receives a total of 15,581 weekly downloads. As such, browser-image-resizer popularity was classified as popular.
We found that browser-image-resizer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.