admin管理员组文章数量:1323200
How to reduce the size of a base64 String for a Jpeg Image? I have the base64 of a 2000x1000px photo. How to get the 500x250px base64 pressed photo? Someone can help me?
How to reduce the size of a base64 String for a Jpeg Image? I have the base64 of a 2000x1000px photo. How to get the 500x250px base64 pressed photo? Someone can help me?
Share Improve this question asked May 9, 2012 at 9:47 KeyserSKeyserS 212 silver badges3 bronze badges 1-
use it's data url to load it as an image, render it (resized) to a canvas element, store the result from
toDataURL
. – Yoshi Commented May 9, 2012 at 9:53
1 Answer
Reset to default 6put the base64 in an image tag
var img = document.createElement("img");
img.src = "data:image/gif;base64," + yourBase64;
draw it to a scaled canvas
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.scale(0.25, 0.25);
ctx.drawImage(img);
get the base64
var base64 = canvas.toDataURL("image/jpeg");
I didn't actually test this so the resizing part might be wrong, but it would be something like this.
try searching how to resize images using the canvas tag.
本文标签: CompressResize jpeg and get the Base64 in JavascriptStack Overflow
版权声明:本文标题:CompressResize jpeg and get the Base64 in Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742090093a2420211.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论