lciolecki/webshot

PHP 应用程序,用于生成网页截图

安装: 11

依赖: 0

建议者: 0

安全: 0

星星: 1

关注者: 0

分支: 0

开放问题: 0

类型:应用程序

dev-master 2014-03-22 13:04 UTC

This package is not auto-updated.

Last update: 2020-01-10 15:22:13 UTC


README

Webshot 屏幕服务器是一个生成网站截图的 Web 应用程序。系统基于 CutyCapt 应用程序 (http://cutycapt.sourceforge.net)。它允许您截取任何网页的截图并将它们保存为 png 格式的图片。应用程序是用 PHP 技术创建的,并使用了 Zend Framework 以及 Doctrine 2。

所需:xvfb-run 和 cutycapt 应用程序。

可用选项:url,min-width,min-height,max-wait,delay,user-style-path,user-style-string,header,method,body-string,body-base64,app-name,app-version,user-agent,app,javascript,java,plugins,private-browsing,auto-load-images,js-can-open-windows,js-can-access-clipboard,print-backgrounds,zoom-factor,zoom-text-only,http-proxy。

## 使用 Composer 安装

{
    "minimum-stability": "dev",
    "require": {
        "lciolecki/webshot": "dev-master"
    }
}

重要:为了正确安装,请使用:composer install -o

# 在 Zend Framework 中的示例使用

public function webshotAction()
{
        $params = array(
          'url' => 'http://google.pl',
          'hash' => '2131sada', //unique identifcator of service
          'sign' => 'adad13123' //sign key for http://google.pl + 2131sada
        );
        
        $url = 'yourdomain/api/create';            
        $client = new Zend_Http_Client($url);
        $client->setMethod(Zend_Http_Client::POST)
               ->setHeaders('X-Requested-With', 'XMLHttpRequest') 
               ->setParameterPost($params)
               ->setConfig(array('timeout' => 180));
        
        $response = $client->request();
        
        $return = Zend_Json::decode($response->getBody());
        $code = isset($return['code']) ? $return['code'] : 200;
    
      if ($code === 200) {
          $this->_helper->viewRenderer->setNoRender(true);
          $this->_helper->layout->disableLayout();
          
          $content = file_get_contents($return['image']);
          $this->getResponse()->setHeader('Content-type', 'image/png');
          $this->getResponse()->setBody($content);
          $this->getResponse()->sendResponse();  
        } else {
          throw new Exception('An error on generate screenshot');
        }
    }