将 Base64 转换为普通 PNG 以进行复制/粘贴
我有一个 HTML 电子邮件模板,它使用了如下的错误流程:
- 从 MySQL 中提取数据并将其放入 HighCharts 图表中
- 使用 canvg 将 HighCharts SVG 转换为画布
- 使用 canvas.toDataURL 将画布渲染为 Base64 PNG
一切都很好,图像显示正常(除了 Internet Explorer 中的一些奇怪之处),但问题是:
我希望用户能够将整个网页复制并粘贴到 Outlook 中并发送将其作为电子邮件发送。然而,Outlook(以及我尝试过的其他一些客户端)不会通过复制粘贴接收 Base64 PNG——图像应该存在的地方有一个空白。
有谁知道如何将 Base64 转换为普通 PNG,以便它可以在复制/粘贴后保存下来?也许这需要将 PNG 保存到服务器?
I've got an HTML email template that's using a kludgy process as follows:
- Pull data from MySQL and put it into a HighCharts chart
- Convert the HighCharts SVG to canvas using canvg
- Render the canvas as a Base64 PNG using canvas.toDataURL
All's well and good, the image shows up fine (except for some quirkiness in Internet Explorer), but here's the rub:
I'd like users to be able to copy and paste the entire web page into Outlook and send it out as an email. However, Outlook (and a few other clients I've tried) won't receive Base64 PNGs via copy paste -- there's a blank space where the image should be.
Does anyone know of a way to convert the Base64 into a normal PNG such that it can survive the copy/paste? Maybe this requires saving the PNG to server?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自从你上一个问题以来,我一直在思考这个问题,并提出了 3 个选择:
一个
两个
在后端,生成发布请求 (类似此处描述的内容请参阅使用 PHP 进行 POST 请求)到位于 http://export.highcharts.com/。通过查看 highcharts 源,请求需要包含以下发布的变量:
<块引用>
文件名:png 文件名
类型:来自绘图选项、类型、线条、条形等。
width:所需 png 的宽度(以像素为单位)
svg:svg 字符串
获取生成的 PNG,将其保存到您的服务器,正常提供服务。
三
切换到使用 Java Highcharts API 。你必须让它在你的服务器上运行。不过,一旦完成,您就可以完全在后端生成图表并只提供 PNG 文件。
I've been thinking about this since your last question and I've come up with 3 options:
One
Two
On the backend, generate a post request (something like described here see Using PHP for POST Request) to the highcharts exporting server at http://export.highcharts.com/. From looking at the highcharts source the request needs to contain the following posted variables:
Get the resulting PNG, save it to your server, serve it normally.
Three
Switch to using the Java Highcharts API. You'd have to get this running on your server. Once you did, though, you could generate your charts entirely on the backend and just serve up the PNG file.