humanemulator.net — справка. Продукт, демо и покупка — на хуманэмулятор.рф | Демо | Купить | API | лог изменений

print_screen

print_screen($filepath,$xl=-1,$yt=-1,$xr=-1,$yb=-1,$as_gray=false); - сделать скриншот текущей страницы (видимой части)

Функция на вход принимает параметры:

  • $filepath – путь к файлу, куда будет сохранен скриншот (поддерживаются форматы bmp,png,gif,jpeg)
  • $xl – x - координата левого верхнего угла страницы для скриншота (при -1 - от начала страницы)
  • $yt – y - координата левого верхнего угла страницы для скриншота (при -1 - от начала страницы)
  • $xr – x - координата правого нижнего угла страницы для скриншота (при -1 - до конца страницы)
  • $as_gray – указывает делать скриншот в сером цвете (true), доступен с версии 7.0.6

    После отработки функция возвращает результат своей работы в скрипт :
  • true – удалось сохранить скриншот в заданный файл
  • false – не удалось сохранить скриншот в заданный файл

    Пример использования
    <?php
    // Scenario: Print webpage screen to image files
    
    $xhe_host = "localhost:7010";
    if (!isset($path)) {
      // Path to the init.php file for connecting to the XHE API
      $path = "../../../Templates/init.php";
      // Including init.php grants access to all classes and functionality for working with the XHE API
      require($path);
    }
    
    // Start
    echo "\n<font color=blue>webpage->" . basename(__FILE__) . "</font>\n";
    
    // Step 1: Navigate to website
    $url = "https://www.yahoo.ru";
    echo "1. Navigate to: ";
    echo WEB::$browser->navigate($url) . "\n";
    sleep(2);
    
    // Example 1: Print entire page
    $filePath1 = "c:\\yahoo.png";
    echo "2. Print entire page: ";
    echo WEB::$webpage->print_screen($filePath1) . "\n";
    WEB::$browser->set_vertical_scroll_pos(100);
    WEB::$browser->set_horizontal_scroll_pos(100);
    
    // Example 2: Print page section
    $filePath2 = "c:\\yahoo1.jpeg";
    $x2 = 200;
    $y2 = 200;
    $width2 = 400;
    $height2 = 400;
    echo "3. Print page section: ";
    echo WEB::$webpage->print_screen($filePath2, $x2, $y2, $width2, $height2) . "\n";
    
    // Example 3: Print page top
    $filePath3 = "c:\\yahoo2.bmp";
    $x3 = -1;
    $y3 = -1;
    $width3 = -1;
    $height3 = 200;
    echo "4. Print page top: ";
    echo WEB::$webpage->print_screen($filePath3, $x3, $y3, $width3, $height3) . "\n";
    
    // Example 4: Print page left section
    $filePath4 = "c:\\yahoo3.gif";
    $x4 = -1;
    $y4 = -1;
    $width4 = 200;
    $height4 = -1;
    echo "5. Print page left section: ";
    echo WEB::$webpage->print_screen($filePath4, $x4, $y4, $width4, $height4) . "\n";
    
    // Example 5: Print entire page (simplified)
    $filePath5 = "c:\\yahoo4.jpeg";
    $x5 = -1;
    $y5 = -1;
    $width5 = -1;
    $height5 = -1;
    $simplified = true;
    echo "6. Print entire page (simplified): ";
    echo WEB::$webpage->print_screen($filePath5, $x5, $y5, $width5, $height5, $simplified) . "\n";
    
    // Step 2: Display printed files
    echo "7. Display printed files: ";
    $app->shell_execute("", $filePath1, "", "c:\\", true);
    sleep(2);
    $app->shell_execute("", $filePath2, "", "c:\\", true);
    sleep(2);
    $app->shell_execute("", $filePath3, "", "c:\\", true);
    sleep(2);
    $app->shell_execute("", $filePath4, "", "c:\\", true);
    sleep(2);
    $app->shell_execute("", $filePath5, "", "c:\\", true);
    sleep(2);
    
    // End
    echo "\n";
    
    // Quit the application
    WINDOW::$app->quit();
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7018"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>webpage.xxxxxxxxx</font><hr>")
    
    # 1 
    echo("1. Перейдем  : ")
    echo(browser.navigate("http://www.yahoo.ru"),"<br>")
    
    # 2 
    echo("2. Распечатаем всю страницу : ")
    echo(webpage.print_screen("c:\\yahoo.jpeg"),"<br>")
    browser.set_vertical_scroll_pos(100)
    browser.set_horizontal_scroll_pos(100)
    
    # 2 
    echo("2. Распечатаем кусок страницы : ")
    echo(webpage.print_screen("c:\\yahoo1.jpeg",200,200,400,400),"<br>")
    
    # 3 
    echo("3. Распечатаем верх страницы : ")
    echo(webpage.print_screen("c:\\yahoo2.jpeg",-1,-1,-1,200),"<br>")
    
    # 4 
    echo("4. Распечатаем левую часть страницы : ")
    echo(webpage.print_screen("c:\\yahoo3.jpeg",-1,-1,200,-1),"<br>")
    
    # 5
    echo("5. Распечатаем всю страницу (упрощенно): ")
    echo(webpage.print_screen("c:\\yahoo4.jpeg",-1,-1,-1,-1,true),"<br>")
    
    # покажем распечатки
    app.shell_execute("","c:\\yahoo.jpeg","","c:\\",true)
    app.shell_execute("","c:\\yahoo1.jpeg","","c:\\",true)
    app.shell_execute("","c:\\yahoo2.jpeg","","c:\\",true)
    app.shell_execute("","c:\\yahoo3.jpeg","","c:\\",true)
    app.shell_execute("","c:\\yahoo4.jpeg","","c:\\",true)
    
    # конец
    echo("<hr><br>")
    
    # Quit
    app.quit()
    #region using
    
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
    
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
    
    #endregion
    
     class Program:XHEScript
     {
    	  static void Main(string[] args)
    	  {
    			// init XHE
    			server = "localhost:7010";
    			InitXHE();
    
    			// начало
    			echo("<hr><font color=blue>webpage.print_screen</font><hr>");
    				
    			// 1 шаг
    			echo("1. Перейдем в гугл : ");
    			echo(browser.navigate("http://www.yahoo.ru")+"<br>");
    			
    			// 2 шаг
    			echo("2. Распечатаем всю страницу : ");
    			echo(webpage.print_screen("c:\\yahoo.jpeg")+"<br>");
    			browser.set_vertical_scroll_pos(100);
    			browser.set_horizontal_scroll_pos(100);
    			
    			// 2 шаг
    			echo("2. Распечатаем кусок страницы : ");
    			echo(webpage.print_screen("c:\\yahoo1.jpeg",200,200,400,400)+"<br>");
    			
    			// 3 шаг
    			echo("3. Распечатаем верх страницы : ");
    			echo(webpage.print_screen("c:\\yahoo2.jpeg",-1,-1,-1,200)+"<br>");
    			
    			// 4 шаг
    			echo("4. Распечатаем левую часть страницы : ");
    			echo(webpage.print_screen("c:\\yahoo3.jpeg",-1,-1,200,-1)+"<br>");
    			
    			// 5 шаг
    			echo("5. Распечатаем всю страницу (упрощенно) : ");
    			echo(webpage.print_screen("c:\\yahoo4.jpeg",-1,-1,-1,-1,true)+"<br>");
    
    			// покажем распечатки
    			app.shell_execute("","c:\\yahoo.jpeg","","c:\\",1);
    			app.shell_execute("","c:\\yahoo1.jpeg","","c:\\",1);
    			app.shell_execute("","c:\\yahoo2.jpeg","","c:\\",1);
    			app.shell_execute("","c:\\yahoo3.jpeg","","c:\\",1);
                app.shell_execute("","c:\\yahoo4.jpeg","","c:\\",1);
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:7018";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>webpage.print_screen</font><hr>");
    
    // 1 шаг
    echo("1. Перейдем  : ");
    echo(browser.navigate("http://www.yahoo.ru")+"<br>");
    
    // 2 шаг
    echo("2. Распечатаем всю страницу : ");
    echo(webpage.print_screen("c:\\yahoo.jpeg")+"<br>");
    browser.set_vertical_scroll_pos(100);
    browser.set_horizontal_scroll_pos(100);
    
    // 3 шаг
    echo("3. Распечатаем кусок страницы : ");
    echo(webpage.print_screen("c:\\yahoo1.jpeg",200,200,400,400)+"<br>");
    
    // 4 шаг
    echo("4. Распечатаем верх страницы : ");
    echo(webpage.print_screen("c:\\yahoo2.jpeg",-1,-1,-1,200)+"<br>");
    
    // 5 шаг
    echo("5. Распечатаем левую часть страницы : ");
    echo(webpage.print_screen("c:\\yahoo3.jpeg",-1,-1,200,-1)+"<br>");
    
    // 6 шаг
    echo("6. Распечатаем всю страницу (упрощенно) : ");
    echo(webpage.print_screen("c:\\yahoo4.jpeg",-1,-1,-1,-1,true)+"<br>");
    
    // покажем распечатки
    app.shell_execute("","c:\\yahoo.jpeg","","c:\\",true);
    app.shell_execute("","c:\\yahoo1.jpeg","","c:\\",true);
    app.shell_execute("","c:\\yahoo2.jpeg","","c:\\",true);
    app.shell_execute("","c:\\yahoo3.jpeg","","c:\\",true);
    app.shell_execute("","c:\\yahoo4.jpeg","","c:\\",true);
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

    =============================================
    Webpage    Объекты    DOM  System  Vision  Web  Window        
    =============================================
    если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум
    .