Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CanvasKitInit not found #36

Open
rylydou opened this issue Sep 26, 2023 · 1 comment
Open

CanvasKitInit not found #36

rylydou opened this issue Sep 26, 2023 · 1 comment

Comments

@rylydou
Copy link

rylydou commented Sep 26, 2023

When running this code using deno run -A ... I get this error: The requested module 'https://deno.land/x/canvas@v1.4.1/mod.ts' does not provide an export named 'CanvasKitInit'

My Code:

import { CanvasKitInit } from "https://deno.land/x/canvas@v1.4.1/mod.ts"

const kit = await CanvasKitInit({
	// What path would you use for locating files in deno?
	locateFile: (file) => '/node_modules/canvaskit-wasm/bin/' + file,
})

const surface = kit.MakeSurface(100, 100)!
const canvas = surface.getCanvas()!

const paint = new kit.Paint()
paint.setColor([255, 0, 0, 255])
canvas.drawCircle(25, 25, 20, paint)

const image = surface.makeImageSnapshot()!
const bytes = image.encodeToBytes()!
Deno.writeFileSync('image.png', bytes)

Before using this package I tried using canvaskit-wasm and got similar errors.

Same code but with a slightly modified header:

import CanvasKitInit from 'npm:canvaskit-wasm'

CanvasKitInit.default({ // ...
@DjDeveloperr
Copy link
Owner

DjDeveloperr commented Oct 3, 2023

mod.ts exports a wrapper API around the canvaskit-wasm, but if you want direct access, you can import canvas from mod.ts which is the already instantiated CanvasKit object.

import { canvas as kit } from "https://deno.land/x/canvas@v1.4.1/mod.ts"

const surface = kit.MakeSurface(100, 100)!
const canvas = surface.getCanvas()!

const paint = new kit.Paint()
paint.setColor([255, 0, 0, 255])
canvas.drawCircle(25, 25, 20, paint)

const image = surface.makeImageSnapshot()!
const bytes = image.encodeToBytes()!
Deno.writeFileSync('image.png', bytes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants