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

base64 image #13

Closed
konsumer opened this issue Sep 12, 2021 · 5 comments
Closed

base64 image #13

konsumer opened this issue Sep 12, 2021 · 5 comments

Comments

@konsumer
Copy link
Contributor

konsumer commented Sep 12, 2021

I am working on this cross-canvas demo to demonstrate using roughly the same code (with a different frame around it) in browser vs deno. I use a base64-image to keep the demo self-contained, and when I run it in deno, I get this:

../deno-pr-buffers/target/debug/deno run --unstable --allow-all ./examples/canvas_cross.js
error: Uncaught (in promise) NotFound: No such file or directory (os error 2)
    data = await Deno.readFile(url);
           ^
    at deno:core/01_core.js:106:46
    at unwrapOpResult (deno:core/01_core.js:126:13)
    at async open (deno:runtime/js/40_files.js:51:17)
    at async Object.readFile (deno:runtime/js/40_read_file.js:20:18)
    at async loadImage (https://deno.land/x/canvas@v1.3.0/src/canvas.ts:28:12)
    at async Object.setup (file:///home/konsumer/Documents/otherdev/deno-minifb/examples/canvas_cross.js:51:19)
    at async mainDeno (file:///home/konsumer/Documents/otherdev/deno-minifb/examples/canvas_cross.js:67:3)

Do I need to do something special to base64 images?

konsumer added a commit to konsumer/deno-canvas that referenced this issue Sep 12, 2021
@konsumer
Copy link
Contributor Author

konsumer commented Sep 12, 2021

I think #14 resolves it. The code was already there, just needed an extra else if to pull out data-urls. Also discovered #15 while working on it.

@DjDeveloperr
Copy link
Owner

Fixed by #14

@konsumer
Copy link
Contributor Author

I am still having issues with this. I made a very simple demo and ran it locally like this:

I run this locally:

import { loadImage, createCanvas } from 'https://deno.land/x/canvas/mod.ts'

const imgData = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYAgMAAACdGdVrAAAACVBMVEUAAADk5+P///9QNmNfAAAAWUlEQVQI112NsQ2AMAwEP8gVlWtKSqYg6zBKKrwDDT8lthUJQnUvv+6NAsUuqKJaJZIW/NA7T3EpE6/AzBvurY3hkTR80Bx142LpHWdA+cI3afkvhQG9G4QH3GofsqbaWK8AAAAASUVORK5CYII='

async function main () {
  const canvas = createCanvas(800, 800)
  const ctx = canvas.getContext('2d')
  ctx.imageSmoothingEnabled = false
  const img = await loadImage(imgData)
  ctx.drawImage(img, 0, 0, canvas.width, canvas.height)
}
main()
deno run -A --reload ./demo.js

error: Uncaught (in promise) NotFound: No such file or directory (os error 2)
    data = await Deno.readFile(url);
           ^
    at deno:core/01_core.js:106:46
    at unwrapOpResult (deno:core/01_core.js:126:13)
    at async open (deno:runtime/js/40_files.js:51:17)
    at async Object.readFile (deno:runtime/js/40_read_file.js:20:18)
    at async loadImage (https://deno.land/x/canvas@v1.3.0/src/canvas.ts:28:12)
    at async main (file:///home/konsumer/Desktop/demo.js:9:15)

it seems like it's still trying to use a local file. I looked at the canvas version that I get linked to, and it's this: https://deno.land/x/canvas@v1.3.0/src/canvas.ts (no new data-url code.) Does it need to be tagged?

@DjDeveloperr
Copy link
Owner

It's not released in any new version yet, you'll have to use main branch/the commit

@konsumer
Copy link
Contributor Author

Sorry, I wasn't thinking. Changing the import works great:

import { loadImage, createCanvas } from 'https://raw.githubusercontent.com/DjDeveloperr/deno-canvas/master/mod.ts'

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