将 HTML 页面转换为图像

发布于 2024-09-24 06:44:18 字数 53 浏览 1 评论 0原文

我想将 HTML 页面更改为图像。 PHP 中有没有办法将 HTML 页面更改或保存为图像?

I want to change my HTML page as an image. Is there a way in PHP to change or save an HTML page as an image?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心房敞 2024-10-01 06:44:20

尝试查看 browsershots.org - 如果您想在本地安装它,可以使用它的源代码。本质上它使用浏览器来截取屏幕截图,并且可以通过 XML-RPC 接口进行控制,您可以从 PHP 调用该接口。

正如其他人所说,这不是一项简单的工作,也不是您可以直接在 PHP 中完成的工作,因此请使用外部服务。

(我不以任何方式隶属于 browsershots.org)

Try taking a look at browsershots.org - source code is available for it if you want to install it locally. Essentially it uses a browser to take screenshots, and can be controlled via an XML-RPC interface, which you can call from PHP.

As others have said this is not a simple job, and not something you can do directly in PHP, so use an external service.

(I'm not affiliated with browsershots.org in any way)

雨夜星沙 2024-10-01 06:44:19

这并不容易;正如 NullUserException 在他的评论中所说,您需要在服务器端呈现 HTML 页面,这不是 PHP(或任何其他服务器端语言)内置的内容。

想到的方法是编写一个程序(可能不是 PHP,而是 C# 或 C++ 等)在服务器上运行,启动 Web 浏览器,并执行一系列屏幕捕获(可能与页面滚动相结合)。由于这是一个非常重要且容易出现错误的过程,因此我建议研究能够执行此操作的第三方组件。

然后,您可以从 PHP 执行该程序,当它运行完成时,显示它输出的文件的结果。

This is not easy; as NullUserException says in his comment, you would need to render the HTML page on the server-side, which is not something PHP (or any other server-sided language) has built in.

The approach that comes to mind would be to write a program (probably not in PHP, but rather something like C# or C++) that runs on your server, fires up a web browser, and does a series of screen captures (possibly combined with page scrolls). As this is a very nontrivial and bug-prone process, I would suggest looking into third-party components that are capable of doing this.

You would then execute this program from PHP, and when it's done running, display the results from the file it output.

不语却知心 2024-10-01 06:44:19

我建议您使用带有 api 的外部服务。此列表可能是一个好的开始:http://blogs.sitepoint.com/2008/07/10/9-ways-to-put-site-screenshots-in-your-web-app/

Thumbalizr 看起来很棒,他们还提供了一个 php 脚本,以便您可以在本地缓存图像:
http://www.thumbalizr.com/apitools.php

I would advise you to use an external service with an api. This list might be a good start: http://blogs.sitepoint.com/2008/07/10/9-ways-to-put-site-screenshots-in-your-web-app/

Thumbalizr seems great, they allso provide a php script so you can cache the images locally:
http://www.thumbalizr.com/apitools.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文