
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@barkleapp/browser-image-resizer
Advanced tools
A browser-based utility to downscale and resize images using OffscreenCanvas
This library allows for cross-browser image downscaling utilizing OffscreenCanvas.
OffscreenCanvas.npm install @barkleapp/browser-image-resizeryarn add @barkleapp/browser-image-resizerpnpm add @barkleapp/browser-image-resizerimport { 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);
}
}
Even large images can be processed in a separate thread using a worker.
import { readAndCompressImage } from "browser-image-resizer";
onmessage = async (e) => {
const converted = await readAndCompressImage(e.data, { maxWidth: 300 });
postMessage(converted, [converted]);
}
const worker = new Worker('worker.js');
const img = document.getElementById('viewer_img');
worker.onmessage = (e) => {
img.src = URL.createObjectURL(e.data);
};
async function convert(file: File) {
const bmp = await createImageBitmap(file);
worker.postMessage(bmp, [bmp]);
}
readAndCompressImage(file, config) => Promise<Blob | OffscreenCanvas>file: An image source that createImageBitmap can read.config: See below| Property Name | Purpose | Default Value |
|---|---|---|
argorithm | Algorithm used for downscaling (see below) | 'null' |
processByHalf | Whether to process downscaling by drawImage(source, 0, 0, source.width / 2, source.height / 2) until the size is smaller than twice the target size. | true |
quality | The quality of jpeg (or webp) | 0.5 |
maxWidth | The maximum width for the downscaled image | 800 |
maxHeight | The maximum height for the downscaled image | 600 |
debug | console.log image update operations | false |
mimeType | specify image output type other than jpeg / If set null, function returns OffscreenCanvas | 'image/jpeg' |
argorithmnull: Just resize with drawImage(). The best quality and fastest.bilinear: Better quality, slower. Comes from upstream (ericnogralesbrowser-image-resizer).hermite: Worse quality, faster. Comes from viliusle/Hermite-resize. Will dispatch workers for better performance.hermite_single: Worse quality, faster. Single-threaded.A Promise that yields an Image Blob or OffscreenCanvas
calculateSize(src, config)calculateSize(src: { width: number; height: number; }, config) => { width: number; height: number; }
With this function you can get the pre-calculated width and height of the resulting image.
The output image is derived from OffscreenCanvas.convertToBlob.
https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/convertToBlob
FAQs
A browser-based utility to downscale and resize images using OffscreenCanvas
We found that @barkleapp/browser-image-resizer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers 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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.