如何在 javascript Filereader 中将 .png 格式的图像转换为 .jpg 格式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23427110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 00:51:40  来源:igfitidea点击:

How to convert image with .png format to .jpg format in javascript Filereader?

javascriptjqueryfilereader

提问by MaRaM

I have developed web application,I am using File reader for pick the image,In that i have to convert the image .png format to .jpeg format.Please help me anyone to complete the task. Thanks in Advance.

我开发了网络应用程序,我正在使用文件阅读器来选择图像,因此我必须将图像 .png 格式转换为 .jpeg 格式。请帮助我完成任务。提前致谢。

回答by Abhas Tandon

This is definitely possible through HTML5 canvas element. Just draw the image in a canvas. (Make the canvas element hidden if you want). Then use canvas.toDataURL("image/jpeg");to get the Base64 notation of image in the required format.

这绝对可以通过 HTML5 canvas 元素实现。只需在画布中绘制图像。(如果需要,可以隐藏画布元素)。然后用于canvas.toDataURL("image/jpeg");获取所需格式的图像的 Base64 表示法。

Check out : http://davidwalsh.name/convert-canvas-image

退房:http: //davidwalsh.name/convert-canvas-image