@bowber/canvas-image
v1.0.5
Published
Image Interface like Python PIL base on HTMLCanvasElement
Readme
Image Interface like Python PIL base on HTMLCanvasElement
Install
npm i @bowber/canvas-imageUsage
Most method of CanvasImage class have the same syntax as Image module from Python PIL
View more in Image module from Python PIL here
Examples:
- Create a blank Image
import CanvasImage from '@bowber/canvas-image'
// Create a blank Image with size 2x2 and fill with white color
const image = CanvasImage.new(2, 2, "white");- Open Image from URL
import CanvasImage from '@bowber/canvas-image'
const image = await CanvasImage.open("https://example.com/image.jpg");- Open Local Image
import CanvasImage from '@bowber/canvas-image'
const image = await CanvasImage.openFromLocal(fileObject: File);- Draw Pixel
import CanvasImage from '@bowber/canvas-image'
const image = CanvasImage.new(10, 10);
image.putPixel(0, 0, `white`);
expect(image.colorData(0, 0, 1, 1)).toEqual([255, 255, 255, 255]);- Draw Rectangle
import CanvasImage from '@bowber/canvas-image'
const image = CanvasImage.new(10, 10);
image.fillRect(3, 2, 2, 2, "white");
expect(image.colorData(3, 2, 2, 2)).toEqual([
...[255, 255, 255, 255],
...[255, 255, 255, 255],
...[255, 255, 255, 255],
...[255, 255, 255, 255]
])