0

I wrote this code in app.ts file:

const image = await qrcode(text);
const imgTag = `<img src="${image}" alt="qrcode" />`;
const encoder = new TextEncoder();
await Deno.writeFile("./qr.html", encoder.encode(imgTag));

the problem its to output it's in an HTML file but I want to convert base 64 images to jpg or png. How to do this?

brc-dd
  • 10,788
  • 3
  • 47
  • 67
Cosmin Ciolacu
  • 406
  • 9
  • 29
  • Does this answer your question? [How can I write files in Deno?](https://stackoverflow.com/questions/62019830/how-can-i-write-files-in-deno) – Lawrence Cherone Jul 21 '20 at 13:23

1 Answers1

0

To encode a Uint8Array (which I assume is what qrcode returns) into base64, you can use std/encoding.

import { encode } from 'https://deno.land/std/encoding/base64.ts'

const image = await qrcode(text);
// use correct mime: png or jpeg
const imgTag = `<img src="data:image/png;base64,${encode(image.buffer)}" alt="qrcode" />`;
const encoder = new TextEncoder();
await Deno.writeFile("./qr.html", encoder.encode(imgTag))
Marcos Casagrande
  • 37,983
  • 8
  • 84
  • 98