将div的内容转换为图像 [英] converting contents of a div into an image

查看:125
本文介绍了将div的内容转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个图像编辑器类型的Web应用程序。我有一个主 div ,其中包含许多 div

I am creating an image editor type web application. I have a main div which will contain many div inside it.

当用户点击保存按钮时,我想将主 div 保存为文件夹中的图像。
我尝试使用 Canvas.toDataURL(),但后来我发现我无法在画布标签中放置div(主div)。我也尝试了 imagegrabscreen() php的功能,但它在整个页面加载之前捕获了屏幕,所以没用。

When the user clicks on a save button, I want to save the main div as an image in a folder. I tried doing it using Canvas.toDataURL() but then I found that i cant place a div(main div) inside canvas tags. I also tried imagegrabscreen() function of php but it captured the screen before the whole page is loaded, so it was of no use.

任何人都可以帮助我并建议使用php或javascript实现此方法吗?

Can anybody help me and suggest a way to implement this using php or javascript?

推荐答案

你为什么当你可以使用一个 canvas 并使用适当的画布函数绘制它时,使用一堆 div

Why are you using a bunch of divs when you could just use one canvas and draw on it with proper canvas functions?

大量示例您正在尝试做什么,例如这个

There are plenty of examples of what you're trying to do, such as this one.

这篇关于将div的内容转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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