screenshotmachine php
1.0.0
使用屏幕快照機器捕獲網站屏幕截圖並將網站轉換為PDF - 在線網站屏幕截圖生成器和網站到PDF轉換器。
a)使用PHP的Composer -軟件包管理器
php composer.phar require screenshotmachine/screenshotmachine-phpb)或直接從github.com下載源代碼
首先,您需要在www.screenshotmachine.com網站上創建一個免費/高級帳戶。註冊後,您將在用戶配置文件中看到客戶密鑰。此處也保留了秘密短語。請始終使用秘密短語,當您的API呼叫從公開可用的網站調用時。
在腳本中設置客戶密鑰和秘密短語(如果需要):
$ customer_key = " PUT_YOUR_CUSTOMER_KEY_HERE " ;
$ secret_phrase = "" ; //leave secret phrase empty, if not needed 設置其他選項以滿足您的需求:
//mandatory parameter
$ options [ ' url ' ] = " https://www.google.com " ;
// all next parameters are optional, see our website screenshot API guide for more details
$ options [ ' dimension ' ] = " 1366x768 " ; // or "1366xfull" for full length screenshot
$ options [ ' device ' ] = " desktop " ;
$ options [ ' format ' ] = " png " ;
$ options [ ' cacheLimit ' ] = " 0 " ;
$ options [ ' delay ' ] = " 200 " ;
$ options [ ' zoom ' ] = " 100 " ;有關選項的更多信息,請訪問我們的網站屏幕截圖API。
<?php
$ customer_key = " PUT_YOUR_CUSTOMER_KEY_HERE " ;
$ secret_phrase = "" ; //leave secret phrase empty, if not needed
$ machine = new ScreenshotMachine ( $ customer_key , $ secret_phrase );
//mandatory parameter
$ options [ ' url ' ] = " https://www.google.com " ;
// all next parameters are optional, see our website screenshot API guide for more details
$ options [ ' dimension ' ] = " 1366x768 " ; // or "1366xfull" for full length screenshot
$ options [ ' device ' ] = " desktop " ;
$ options [ ' format ' ] = " png " ;
$ options [ ' cacheLimit ' ] = " 0 " ;
$ options [ ' delay ' ] = " 200 " ;
$ options [ ' zoom ' ] = " 100 " ;
$ api_url = $ machine -> generate_screenshot_api_url ( $ options );
//put link to your html code
echo ' <img src=" ' . $ api_url . ' "> ' . PHP_EOL ;生成的api_url鏈接可以放置在<img>標籤中,也可以在您的業務邏輯中使用。
如果您需要將捕獲的屏幕截圖作為圖像存儲,請致電:
<?php
$ customer_key = " PUT_YOUR_CUSTOMER_KEY_HERE " ;
$ secret_phrase = "" ; //leave secret phrase empty, if not needed
$ machine = new ScreenshotMachine ( $ customer_key , $ secret_phrase );
//mandatory parameter
$ options [ ' url ' ] = " https://www.google.com " ;
// all next parameters are optional, see our website screenshot API guide for more details
$ options [ ' dimension ' ] = " 1366x768 " ; // or "1366xfull" for full length screenshot
$ options [ ' device ' ] = " desktop " ;
$ options [ ' format ' ] = " png " ;
$ options [ ' cacheLimit ' ] = " 0 " ;
$ options [ ' delay ' ] = " 200 " ;
$ options [ ' zoom ' ] = " 100 " ;
$ api_url = $ machine -> generate_screenshot_api_url ( $ options );
//save screenshot as an image
$ output_file = ' output.png ' ;
file_put_contents ( $ output_file , file_get_contents ( $ api_url ));
echo ' Screenshot saved as ' . $ output_file . PHP_EOL ;捕獲的屏幕截圖將作為output.png 。
設置PDF選項:
//mandatory parameter
$ options [ ' url ' ] = " https://www.google.com " ;
// all next parameters are optional, see our website to PDF API guide for more details
$ options [ ' paper ' ] = " letter " ;
$ options [ ' orientation ' ] = " portrait " ;
$ options [ ' media ' ] = " print " ;
$ options [ ' bg ' ] = " nobg " ;
$ options [ ' delay ' ] = " 2000 " ;
$ options [ ' scale ' ] = " 50 " ;有關選項的更多信息,請訪問我們的網站上的PDF API。
$ customer_key = " PUT_YOUR_CUSTOMER_KEY_HERE " ;
$ secret_phrase = "" ; //leave secret phrase empty, if not needed
$ machine = new ScreenshotMachine ( $ customer_key , $ secret_phrase );
//mandatory parameter
$ options [ ' url ' ] = " https://www.google.com " ;
// all next parameters are optional, see our website to PDF API guide for more details
$ options [ ' paper ' ] = " letter " ;
$ options [ ' orientation ' ] = " portrait " ;
$ options [ ' media ' ] = " print " ;
$ options [ ' bg ' ] = " nobg " ;
$ options [ ' delay ' ] = " 2000 " ;
$ options [ ' scale ' ] = " 50 " ;
$ pdf_api_url = $ machine -> generate_pdf_api_url ( $ options );
//save PDF file
$ output_file = ' output.pdf ' ;
file_put_contents ( $ output_file , file_get_contents ( $ pdf_api_url ));
echo ' PDF saved as ' . $ output_file . PHP_EOL ;捕獲的PDF將作為輸出保存為output.pdf文件。
麻省理工學院許可證(MIT)