问题描述
如何用PHP渲染网页并将其另存为图像,宽度可能为600px.如何在不使用浏览器的情况下用PHP呈现页面?如何以给定的分辨率和图像格式(jpeg)保存它?该功能与Google预览相似,但不会在过渡中显示.
How can you render and save a web page as an image in PHP, probably with a width of 600px. How can I render a page in PHP without using a browser? How can I save it with a given resolution and image format (jpeg)? The functionality is similar to Google Preview, except it will not be displayed in a rollover.
类似于此问题,用C#回答.如何将网页另存为图像
Similar to this question, which is answered in C#. How to save a web page as image
谢谢!
推荐答案
您应该获得 wkhtmltoimage
,在PHP中非常容易使用:
You should get wkhtmltoimage
, which is very easy to utilize from within PHP:
exec("../wkhtmltoimage --crop-w 600 http://example.com/ output.png");
还有其他选择,而不是-crop-w
或-width 600
然后使用GD或imagemagick.
There are other options, and instead of --crop-w
or --width 600
it might be better to downscale it using GD or imagemagick afterwards.
这篇关于如何使用PHP创建网页图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!