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.
bun-image-size
Advanced tools
The processor can handle absolute file paths or URLs to remote images and ofcourse you can pass the image's raw data as an ArrayBuffer too.
Currently the package can only identify and measure the following image types:
import {createProcessor} from 'bun-image-size';
const processor = createProcessor('https://picsum.photos/500/400')
.onError((error) => console.log(error));
const result = await processor.process();
/** result
* {
* type: "image/png", // Mime type
* size: 123009, // The byte length
* width: 500, // Pixels
* height: 400 // Pixels
* }
*/
The example above registers the processor with the URL supplied immediately. The URL is optional on initialization. If ommitted and process is called without a location too, an error will be reported.
import {createProcessor} from 'bun-image-size';
const processor = createProcessor(import.meta.dir + '/image.png')
.onError((error) => console.log(error));
const result = await processor.process();
/** result
* {
* type: "image/png", // Mime type
* size: 123009, // The byte length
* width: 500, // Pixels
* height: 400 // Pixels
* }
*/
import {createProcessor} from 'bun-image-size';
let imageBuffer; /* get the buffer from somewhere */;
const processor = createProcessor()
.onError((error) => console.log(error));
const result = await processor.processArrayBuffer(imageBuffer);
/** result
* {
* type: "image/png", // Mime type
* size: 123009, // The byte length
* width: 500, // Pixels
* height: 400 // Pixels
* }
*/
You can use the helper to identify an image's Mime type in Bun.
import {createMimeIdentifier} from 'bun-image-size';
let imageBuffer: ArrayBuffer; // Get the image buffer from somewhere.
const identifier = createMimeIdentifier(imageBuffer);
const mimeType: string = await identifier.identify(); // image/png
import {createProcessor} from 'bun-image-size';
const processor = createProcessor(import.meta.dir + '/image.png');
const buffer = processor.buffer // Undefined
await processor.process();
const bufferNow = processor.buffer // ArrayBuffer
All tests conducted on:
Runtime + type | Test Duration | Number of iterations | Iterations per second |
---|---|---|---|
NodeJS + JPG | 10,000ms | 251,838 | 25,184 |
Bun + JPG | 10,000ms | 494,257 | 49,426 (1.96x faster) |
NodeJS + PNG | 10,000ms | 237,057 | 23,706 |
Bun + PNG | 10,000ms | 1,212,458 | 121,246 (5.11x faster) |
NodeJS + SVG | 10,000ms | 193,883 | 19,388 |
Bun + SVG | 10,000ms | 663,204 | 66,320 (3.42x faster) |
NodeJS + ICO | 10,000ms | 252,128 | 25,213 |
Bun + ICO | 10,000ms | 1,037,482 | 103,748 (4.11x faster) |
All tests were validated and 0% of the tests gave invalid results. The image sizes varied in the different formats, but they were exactly the same across Runtime tests. The NodeJS version uses image-size
FAQs
A tiny library to process image sizes and types
The npm package bun-image-size receives a total of 1 weekly downloads. As such, bun-image-size popularity was classified as not popular.
We found that bun-image-size 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.