denorg / qrcode

📇 Generate QR code images in Deno
https://denorg.github.io/qrcode/
MIT License
42 stars 11 forks source link

默认返回gif格式的base64,有没有参数指定或修改返回的格式? #8

Open dong-lufei opened 2 years ago

dong-lufei commented 2 years ago

data:image/gif;base64,base64编码的gif图片数据 data:image/png;base64,base64编码的png图片数据

edu-sonya-cc commented 1 year ago

The developer is not Chinese, so I suggest you use English to ask questions. By the way, I am also a Chinese, and my English is very poor. I usually use Baidu Translation to solve this problem. This library was last updated on December 5, 2020, so I suggest you solve this problem with other libraries.

Maybe imagescript or imagemagick can help you. Please refer to: https://deno.land/x/imagescript @v1.2.14/mod.ts https://deno.land/x/imagemagick_deno @0.0.14/mod.ts

This is a sample, I use other libraries to solute another problem: https://github.com/denorg/qrcode/issues/9

=========================================================================== 开发者并非中国人,因此建议您使用英文进行提问。顺便说说,我也是一名中国人,而且我的英语挺差的,通常我使用百度翻译来解決这个问题。 这个库上次更新于2020年12月5日,所以建议您结合其它库来解决这个问题。

也许deno库imagescript或imagemagick能帮助到您,请参考: https://deno.land/x/imagescript@v1.2.14/mod.ts https://deno.land/x/imagemagick_deno@0.0.14/mod.ts

以下是我结合其它库来解决另一个问题的例子: https://github.com/denorg/qrcode/issues/9

JJ commented 1 year ago

OK, I'll answer in English, if you don't mind. For the time being, no, that's the format returned, with the intention that it's included directly in an HTML img tag. As @edu-sonya-cc says (thanks!), converting it to an actual image can be achieved by using another library, or using these lines:

const data = base64string.slice(22);
const bytes = Uint8Array.from(atob(data), (c) => c.charCodeAt(0));
await Deno.writeFile("tests/test.gif", bytes);

We might include that as an upgrade to this library, it wouldn't be too hard.