php 用php从html生成图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6702986/
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-08-26 01:02:25  来源:igfitidea点击:

Generate image from html with php

phphtmlimagegd

提问by Julien Ducro

For some security reasons, I would like to generate an image based on Google Calendar embed iframe, to be able to show it on a website who don't allow iframes.

出于某些安全原因,我想生成一个基于 Google 日历嵌入 iframe 的图像,以便能够在不允许 iframe 的网站上显示它。

Is there any php library to create an image from html?

是否有任何 php 库可以从 html 创建图像?

The script have to be executable on a linux server.

该脚本必须在 linux 服务器上可执行。

采纳答案by Julien Ducro

The library wkhtmltoimageworks perfectly.

wkhtmltoimage完美运行。

I have created a page to embed the google calendar (the url can't be reach directly).

我创建了一个页面来嵌入谷歌日历(无法直接访问 url)。

I generate a picture from this page and I link this image on my profile on the website.

我从此页面生成了一张图片,并将此图片链接到我在网站上的个人资料中。

Thanks heaps for the comments.

感谢堆的意见。

回答by Sudantha

functions from the GD library to output an image of the current screen

GD 库中的函数,用于输出当前屏幕的图像

<?php
//All of your normal code would go here
//But before exiting, grab a snapshot
$image = imagegrabscreen();
imagejpeg($image,"my_screenshot.jpeg");
imagedestroy($image);
?>

Or use

或使用

websnaprlets you capture screenshots of (almost) any web page. Allow your visitors to instantly visualize any web page before clicking. Increase site traffic, click-through rate and site stickiness.

websnapr可让您捕获(几乎)任何网页的屏幕截图。允许您的访问者在单击之前立即可视化任何网页。增加网站流量、点击率和网站粘性。