减少画布生成的图像文件的大小? [英] Reduce the size of generated image files from canvas?

查看:121
本文介绍了减少画布生成的图像文件的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个模因生成器。它的问题是我从画布获得的图像有很大的尺寸。典型大小为600KB。这是正常的吗?我可以做些什么来缩小图像尺寸吗?我会发布代码,但我不认为代码很重要。

I have create a meme generator. The problem with it is that the image I get from canvas have large size. Typical size is 600KB. Is it normal? Can I do something to reduce the image size? I would post the code but I don't think the code matters.

推荐答案

您可以通过指定<来减小URL大小code> toDataURL 使用jpg编码而不是png。

You can reduce the URL size by specifying that toDataURL encode using jpg instead png.

var jpgURL = canvas.toDataURL("image/jpeg");

您还可以指定图像质量以进一步缩小网址大小。

You can also specify an image quality to further reduce the URL size.

var jpgURLat50PercentQuality = canvas.toDataURL("image/jpeg", 0.5);

祝你的项目好运!

这篇关于减少画布生成的图像文件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆