我正在尝试捕获一些Web URL的屏幕截图,因此,为此,我在Google上搜索了多达10个页面的所有内容,但没有发现任何让我头脑清醒的东西,因此终于在这里寻求帮助。
为了对我的URL进行更好的截屏,在搜索了许多插件,API和代码之后,我发现PhantomJS
非常可靠,并被许多开发人员推荐。最后,我创建了脚本以使用Windows 10捕获以下屏幕截图,Wamp Local Server稍后将在基于Linux的共享Web托管服务器上托管我的脚本。1。)首先,我从https://phantomjs.org/
下载了用于Windows(.exe)文件的PhantomJS,并将其保存在D:\Wamp_Server_64\www\MyProject\bin\phantomjs.exe
文件夹中。2。)创建了一些下面的文件作为基础。
PHP文件(capture.php):
<?php $response = exec('D:\Wamp_Server_64\www\MyProject\bin\phantomjs D:\Wamp_Server_64\www\MyProject\js\screenshot.js http://www.google.com google.jpg'); ?>
JS文件(screenshot.js):
的同一文件夹中。var system = require('system'); // Web Address (URL) of the page to capture var url = system.args[1]; // File name of the captured image var file = system.args[2]; var page = require('webpage').create(); // Browser size - height and width in pixels // Change the viewport to 480x320 to emulate the iPhone page.viewportSize = { width: 1200, height : 800 }; //the clipRect is the portion of the page you are taking a screenshot of page.clipRect = { top: 0, left: 0, width: 1200, height: 600 }; // Set the User Agent String // You can change it to iPad or Android for mobile screenshots page.settings.userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5"; // Render the screenshot image page.open ( url, function ( status ) { if ( status !== "success") { console.log("Could not open web page : " + url); phantom.exit(); } else { window.setTimeout ( function() { page.render(file); console.log("Download the screenshot : " + file); phantom.exit(); }, 1000); } });
3。)现在,在通过
capture.php
在浏览器中运行http://localhost/MyProject/capture.php
文件之后,我将文件google.jpg
下载到capture.php
现在我遇到了一些彼此相关的问题,需要下面分享的建议。
capture.php
页面上显示屏幕截图而不是下载。http://localhost/MyProject/capture.php?URL=XXXXXX&Width=XXXXXX&Height=XXXXXX&FileName=XXXXXX&CropWidth=XXXXXX&CropHeight=XXXXXX
这样的API,然后应该可以在MyProject<img src="http://localhost/MyProject/capture.php?URL=XXXXXX&Width=XXXXXX&Height=XXXXXX&FileName=XXXXXX&CropWidth=XXXXXX&CropHeight=XXXXXX"/>
。 (注意:为此,我尝试研究[https://github.com/jonnnnyw/php-phantomjs和https://github.com/microweber/screen/tree/master/demo,但无法学习)我知道我问的太多了,但是我坚持这些步骤。休息,我从谷歌搜索中得到了全部。 :) #HappyCoding
我正在尝试捕获一些Web URL的屏幕快照,因此,为此,我在Google上搜索了多达10个页面的所有内容,但没有发现任何让我头脑清醒的东西,因此终于在这里寻求帮助。要有一个...
您需要HTML才能显示图像。 PHP
仅执行处理。尝试在HTML上渲染图像最后,我通过使用PhantomJS - renderBase64()
的https://phantomjs.org/api/webpage/method/render-base64.html函数从PhantomJS