PHP实现网页截图是一个在平常开发中不常见的需求,可是若是实现仍是很是有意思的。目前业界有不少成熟的方案,下面我推荐使用一个很稳定的第三方服务来直接实现,该服务有以下特色:api
首先咱们打开 它的首页 https://www.screenshotmaster.com/ 注册一个帐号,而后你会在用户中心获取到一个惟一的Token,保存好这个Token 不要泄漏!url
下面来看看它支持的参数:spa
您能够前往API文档页面查看更多的参数。code
使用PHP调用截屏大师的接口获取截图:blog
//参数 $token = 'YOUR_API_TOKEN'; $url = urlencode('https://www.baidu.com'); $width = 1200; $height = 800; $full_page = 1; // 构造URL $query = "https://www.screenshotmaster.com/api/v1/screenshot"; $query .= "?token=$token&url=$url&width=$width&height=$height&full_page=$full_page"; // 调用API $image = file_get_contents($query); // 保存截图 file_put_contents('./screenshot.png', $image);
而后?没有而后了,就这么简单!
Enjoy Yourself!token