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

resize

resize($inpath,$outpath,$scale,$scaleType=1); - масштабировать картинку доступна с версии 7.0.56

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

  • $inpath – путь к исходной картинки (может быть относительным)
  • $outpath – путь к новой картинке (может быть относительным)
  • $scale – масштаб, например: 2 = 200%, 0.5 =50%
  • $scaleType – тип масштабирования:
    • 0 - интерполяция методом ближайшего соседа (nearest-neighbor interpolation)
    • 1 - билинейная интерполяция (bilinear interpolation используется по умолчанию)
    • 2 - бикубическая интерполяция (bicubic interpolation) в окрестности 4x4 пикселей
    • 3 - передискретизации с использованием отношения площади пикселя
    • 4 - интерполяция Ланцоша (Lanczos interpolation) в окрестности 8x8 пикселей
    • 5 - билинейная точная интерполяция (bilinear exact interpolation)

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

    Пример использования
    <?php
    // Scenario: Resize an image with different scale types
    $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);
    }
    
    // Path to the source image
    $sourceImagePath = "images/original_image.png";
    
    // Make sure the source image file exists
    if (file_exists($sourceImagePath)) {
        echo "Source image found at: " . $sourceImagePath . "\n";
        
        // Example 1: Resize image to 200% (double the size) using bilinear interpolation (default)
        $resizedImagePath1 = "images/resized_200_percent.png";
        $scale1 = 2.0;  // 200% of original size
        $scaleType1 = 1; // Bilinear interpolation
        
        echo "Resizing image to 200% using bilinear interpolation...\n";
        $result1 = DOM::$image->resize($sourceImagePath, $resizedImagePath1, $scale1, $scaleType1);
        
        if ($result1) {
            echo "Successfully resized image to 200%\n";
            echo "Resized image saved to: " . $resizedImagePath1 . "\n";
            
            // Verify the new image was created
            if (file_exists($resizedImagePath1)) {
                $fileSize1 = filesize($resizedImagePath1);
                echo "Resized image file size: " . $fileSize1 . " bytes\n";
            } else {
                echo "Warning: Resized image file was not created\n";
            }
        } else {
            echo "Failed to resize image to 200%\n";
        }
    
    } else {
        echo "Source image file not found at: " . $sourceImagePath . "\n";
        
        // For demonstration purposes
        echo "For this example to work, you would need an image file at: " . $sourceImagePath . "\n";
    }
    
    // Quit the application
    WINDOW::$app->quit();
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7024"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>image.xxxxxxxxx</font><hr>")
    
    # 1
    echo("1. Уменьшим картинку до 30% : ");
    echo(image.resize("test\\test.jpg","test\\test_resize.jpg", 0.3),"\n");
    
    # 2
    echo("2. Покажем результат : ");
    echo(app.shell_execute("open","test\\test_resize.jpg"));
    
    # конец
    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>image.add_image</font><hr>");
    							
    			// 1
    			echo("1. Уменьшим картинку до 30% : ");
    			echo(image.resize("test\\test.jpg","test\\test_resize.jpg", 0.3)+"\n");
    
    			// 2
    			echo("2. Покажем результат : ");
    			echo(app.shell_execute("open","test\\test_resize.jpg"));
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:7024";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>image.add_image</font><hr>");
    
    // 1
    echo("1. Уменьшим картинку до 30% : ");
    echo(image.resize("test\\test.jpg","test\\test_resize.jpg", 0.3)+"\n");
    
    // 2
    echo("2. Покажем результат : ");
    echo(app.shell_execute("open","test\\test_resize.jpg"));
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

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