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

get_dpi

get_dpi($path,$is_horizontal=true,$in_pixels=false); - Получить плотность пикселей картинки по диагонали/горизонтали/вертикали

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

  • $path – путь к исходной картинке
  • $is_horizontal – true - получить DPI картинки по горизонтали, иначе по вертикали
  • $in_pixels – true - в пикселях, иначе в дюймах

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

    Пример использования
    <?php
    // Scenario: Get the DPI (Dots Per Inch) of an image. This function retrieves the resolution information of an image, which is important for printing and quality assessment.
    $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);
    }
    
    // Check if the source image exists
    $sourceImage = "sample_image.png";
    if (file_exists($sourceImage)) {
        // Get the image width in DPI
        echo "Getting width of image: $sourceImage\n";
    
        $widthDpi = DOM::$image->get_dpi($sourceImage, true);
    
        if ($widthDpi != -1) {
            echo "Image width in DPI: $widthDpi\n";
        } else {
            echo "Failed to get DPI of the image\n";
        }
    
        // Get the image height in DPI
        echo "Getting height of image: $sourceImage\n";
    
        $heightDpi = DOM::$image->get_dpi($sourceImage, false, true);
    
        if ($heightDpi != -1) {
            echo "Image width in DPI: $heightDpi\n";
        } else {
            echo "Failed to get DPI of the image\n";
        }
    
        // Get the image width in pixels
        echo "Getting width of image: $sourceImage\n";
    
        $width = DOM::$image->get_dpi($sourceImage, true, true);
    
        if ($width != -1) {
            echo "Image width in pixels: $width\n";
        } else {
            echo "Failed to get pixels of the image\n";
        }
    
        // Get the image height in pixels
        echo "Getting height of image: $sourceImage\n";
    
        $height = DOM::$image->get_dpi($sourceImage, false);
    
        if ($height != -1) {
            echo "Image width in pixels: $height\n";
        } else {
            echo "Failed to get pixels of the image\n";
        }
    }
    else {
        echo "Source image does not exist: $sourceImage\n";
    }
    // Quit the application
    WINDOW::$app->quit();
    ?>
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7010"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>image.get_dpi</font><hr>")
    
    # 1 шаг
    echo("1. Вызовем метод get_dpi : ");
    result = image.get_dpi("path", True, False)
    echo(result);
    
    # конец
    echo("<hr><br>")
    
    # уведомляем среду что скрипт закончил работать
    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>image.get_dpi</font><hr>");
    
    			// 1 шаг
    			echo("1. Вызовем метод get_dpi : ");
    			dynamic result = image.get_dpi("path", true, false);
    			echo(result+"\n\n");
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:7010";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>image.get_dpi</font><hr>");
    
    // 1 шаг
    echo("1. Вызовем метод get_dpi : \n");
    var result = image.get_dpi("path", true, false);
    echo(result+"\n");
    
    // конец
    echo("\n");
    
    // уведомляем среду что скрипт закончил работать
    app.quit();

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