在PHP网页上显示图像,而不是使用PhantomJS下载

问题描述 投票:1回答:2

我正在尝试捕获一些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

的同一文件夹中。

问题:

现在我遇到了一些彼此相关的问题,需要下面分享的建议。

  1. 首先,主要问题是我想在capture.php页面上显示屏幕截图而不是下载。
  2. 第二是它生成的图像太重,因此我想降低其缩略图的质量。
  3. 第三个问题是,我想使其像http://localhost/MyProject/capture.php?URL=XXXXXX&Width=XXXXXX&Height=XXXXXX&FileName=XXXXXX&CropWidth=XXXXXX&CropHeight=XXXXXX这样的API,然后应该可以在MyProject
  4. 中的任何地方将其用作<img src="http://localhost/MyProject/capture.php?URL=XXXXXX&Width=XXXXXX&Height=XXXXXX&FileName=XXXXXX&CropWidth=XXXXXX&CropHeight=XXXXXX"/>。 (注意:为此,我尝试研究[https://github.com/jonnnnyw/php-phantomjshttps://github.com/microweber/screen/tree/master/demo,但无法学习)
  5. 第四,浏览器网站图标保持动画状态需要花费太多时间,我想稍后将其托管在基于Linux的通用共享网站服务器上,以便如何快速加载它并希望显示一个常规加载图像,直到生成缩略图。
  6. 我知道我问的太多了,但是我坚持这些步骤。休息,我从谷歌搜索中得到了全部。 :) #HappyCoding

我正在尝试捕获一些Web URL的屏幕快照,因此,为此,我在Google上搜索了多达10个页面的所有内容,但没有发现任何让我头脑清醒的东西,因此终于在这里寻求帮助。要有一个...

javascript php image phantomjs bin
2个回答
0
投票

您需要HTML才能显示图像。 PHP

仅执行处理。尝试在HTML上渲染图像

0
投票

最后,我通过使用PhantomJS - renderBase64()https://phantomjs.org/api/webpage/method/render-base64.html函数从PhantomJS

© www.soinside.com 2019 - 2024. All rights reserved.