New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@canvas/image

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@canvas/image

An `Image` implementation for usage outside of the browser.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.7K
decreased by-72.93%
Maintainers
1
Weekly downloads
 
Created
Source

Image

An Image implementation for usage outside of the browser.

Also exports some helper methods which are available both in Node.js, and in the browser when packaging with Browserify, Webpack, etc.

Installation

npm install --save @canvas/image

Usage

const fs = require('fs')
const { Image, getImageData, imageFromBuffer, imageFromImageData } = require('@canvas/image')

// Traditional loading
const img = new Image()
img.src = 'image.png'
img.onload = () => {
  console.log(img.width)
  // => 2

  console.log(img.height)
  // => 1

  console.log(getImageData(img).data)
  // => Uint8ClampedArray [ 1, 2, 3, 4, 5, 6, 7, 8 ]
}

// From Buffer
const source = fs.readFileSync('image.png')
imageFromBuffer(source).then((img) => {
  console.log(img.width)
  // => 2

  console.log(img.height)
  // => 1

  console.log(getImageData(img).data)
  // => Uint8ClampedArray [ 1, 2, 3, 4, 5, 6, 7, 8 ]
})

// From ImageData
const data = new ImageData(new Uint8ClampedArray([1, 2, 3, 4, 5, 6, 7, 8]), 2, 1)
imageFromImageData(data).then((img) => {
  console.log(img.width)
  // => 2

  console.log(img.height)
  // => 1

  console.log(getImageData(img).data)
  // => Uint8ClampedArray [ 1, 2, 3, 4, 5, 6, 7, 8 ]
})

API

getImageData(image)

  • image (Image, required)
  • returns ImageData or undefined

imageFromBuffer(buffer)

  • buffer (Uint8Array, required)
  • returns Promise<Image>

imageFromImageData(imageData)

  • imageData (ImageData, required)
  • returns Promise<Image>

Hacking

The tests are made to be run against both this implementation and Chrome's implementation to make sure that we behave in the same way. You can run the tests in Chrome by building the test bundle (npm run build), spinning up a local web server, and then opening test.html.

FAQs

Package last updated on 26 Jul 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc