
Security News
rv Is a New Rust-Powered Ruby Version Manager Inspired by Python's uv
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
@larscom/image-data
Advanced tools
create ImageData object from URL or ArrayBuffer without creating a canvas (using wasm)
Easily construct an Image
object from a URL or ArrayBuffer. An Image
object contains the width and height of the image and an ImageData
object as well as the channels (RGBA). It uses WASM
to construct such an object.
npm install @larscom/image-data
Import the load_from_url
function to construct an Image
object.
import { load_from_url } from '@larscom/image-data'
const imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png'
const image = await load_from_url(imageUrl)
const canvas = document.getElementById('canvas')
canvas.width = image.width
canvas.height = image.height
const ctx = canvas.getContext('2d')
// use the ImageData object
ctx.putImageData(image.data, 0, 0)
interface Image {
width: number
height: number
data: ImageData
// RGBA
channels: Uint8Array<ArrayBuffer>
}
When using a build tool such as vite you need additional configuration as it doesn't serve *.wasm files by default (see examples folder for a vite-react-ts
project)
add
exclude
option tooptimizeDeps
tovite.config.ts
export default defineConfig({
plugins: [react()],
optimizeDeps: {
exclude: ['@larscom/image-data']
}
})
Convert each individual pixel to a HEX color code.
import { load_from_url, convert_to_hex_colors } from '@larscom/image-data'
const imageUrl = 'https://example.com/image.png'
const image = await load_from_url(imageUrl)
const colors = convert_to_hex_colors(image.channels)
console.log(colors) // ["#FF5733", "#33C1FF", "#28A745", ...]
Decode the raw channel data into an array of pixels (RGBA)
import { load_from_url, decode_to_rgba } from '@larscom/image-data'
const imageUrl = 'https://example.com/image.png'
const image = await load_from_url(imageUrl)
const pixels = decode_to_rgba(image.channels)
console.log(pixels)
// [
// { r: 255, g: 0, b: 0, a: 255 },
// { r: 0, g: 255, b: 0, a: 128 },
// { r: 0, g: 0, b: 255, a: 64 },
// ...
// ]
Format | Supported |
---|---|
JPEG | ✅ |
PNG | ✅ |
BMP | ✅ |
DDS | ✅ |
FARBFELD | ✅ |
GIF | ✅ |
HDR | ✅ |
ICO | ✅ |
EXR | ✅ |
PNM | ✅ |
QOI | ✅ |
TGA | ✅ |
TIFF | ✅ |
WEBP | ✅ |
AVIF | ❌ |
SVG | ❌ |
FAQs
create ImageData object from URL or ArrayBuffer without creating a canvas (using wasm)
The npm package @larscom/image-data receives a total of 173 weekly downloads. As such, @larscom/image-data popularity was classified as not popular.
We found that @larscom/image-data demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.