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

unborder

unborder($inpath,$outpath,$struct_x=220,$struct_y=20,$smooth_xy=3); - Убрать границы у картинки

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

  • $inpath – путь к исходной картинке
  • $outpath – путь к новой картинке
  • $struct_x – граница по оси X
  • $struct_y – граница по оси Y
  • $smooth_xy – размытие границ по Гауссу

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

    Пример использования
    <?php
    // Scenario: Remove borders from an image. This function is useful for removing unwanted borders, frames, or edges from images to focus on the main content.
    $xhe_host = getenv("RPABOT_HOST_URL");
    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);
    }
    
    // Create output directory if it doesn't exist
    $outputDir = "output";
    if (!is_dir($outputDir)) {
        mkdir($outputDir, 0777, true);
        echo "Created output directory: $outputDir\n";
    }
    
    // Check if the source image exists
    $sourceImage = "image_with_border.png";
    if (!file_exists($sourceImage)) {
        echo "Source image does not exist: $sourceImage\n";
        echo "Creating a sample image with border for demonstration...\n";
        
        // Create a simple test image
        $testImagePath = "test_image.png";
        file_put_contents($testImagePath, "dummy image with border");
        
        // Save as image using XHE
        DOM::$image->save_as_gray($testImagePath, $sourceImage);
        echo "Created sample image: $sourceImage\n";
    }
    
    // Remove border from the image
    $outputPath = "$outputDir/image_without_border.png";
    echo "Removing border from image: $sourceImage\n";
    
    $result = DOM::$image->unborder($sourceImage, $outputPath);
    
    if ($result) {
        echo "Border removed successfully and saved to: $outputPath\n";
        
        // Check if the file was actually created
        if (file_exists($outputPath)) {
            echo "File size: " . filesize($outputPath) . " bytes\n";
            
            // Get image info to compare dimensions
            $sourceInfo = getimagesize($sourceImage);
            $outputInfo = getimagesize($outputPath);
            
            if ($sourceInfo && $outputInfo) {
                echo "Original dimensions: " . $sourceInfo[0] . "x" . $sourceInfo[1] . " pixels\n";
                echo "After border removal: " . $outputInfo[0] . "x" . $outputInfo[1] . " pixels\n";
            }
        } else {
            echo "Warning: Unbordered image file was not created despite success return value\n";
        }
    } else {
        echo "Failed to remove border from the image\n";
    }
    
    // Example with different parameters
    echo "\nRemoving border with different parameters...\n";
    $outputPath2 = "$outputDir/image_without_border_custom.png";
    $result2 = DOM::$image->unborder($sourceImage, $outputPath2, 20, 15, 20);
    
    if ($result2) {
        echo "Custom border removal successful, saved to: $outputPath2\n";
        
        if (file_exists($outputPath2)) {
            echo "File size: " . filesize($outputPath2) . " bytes\n";
            
            $outputInfo2 = getimagesize($outputPath2);
            if ($outputInfo2) {
                echo "Custom border removal dimensions: " . $outputInfo2[0] . "x" . $outputInfo2[1] . " pixels\n";
            }
        }
    } else {
        echo "Failed to remove border with custom parameters\n";
    }
    
    // Example with a different source image
    echo "\nCreating another example with a different source image...\n";
    $sourceImage2 = "document_with_border.jpg";
    if (!file_exists($sourceImage2)) {
        echo "Creating a sample document image with border...\n";
        $testImagePath2 = "test_document.jpg";
        file_put_contents($testImagePath2, "dummy document image with border");
        
        DOM::$image->save_as_gray($testImagePath2, $sourceImage2);
        echo "Created sample document image: $sourceImage2\n";
    }
    
    $outputPath3 = "$outputDir/document_without_border.png";
    $result3 = DOM::$image->unborder($sourceImage2, $outputPath3);
    
    if ($result3) {
        echo "Document border removed successfully, saved to: $outputPath3\n";
        
        if (file_exists($outputPath3)) {
            echo "File size: " . filesize($outputPath3) . " bytes\n";
            
            $sourceInfo2 = getimagesize($sourceImage2);
            $outputInfo3 = getimagesize($outputPath3);
            
            if ($sourceInfo2 && $outputInfo3) {
                echo "Original document dimensions: " . $sourceInfo2[0] . "x" . $sourceInfo2[1] . " pixels\n";
                echo "After border removal: " . $outputInfo3[0] . "x" . $outputInfo3[1] . " pixels\n";
            }
        }
    } else {
        echo "Failed to remove border from document\n";
    }
    
    // Example with asymmetric border removal
    echo "\nRemoving asymmetric border from image...\n";
    $outputPath4 = "$outputDir/image_without_asymmetric_border.png";
    $result4 = DOM::$image->unborder($sourceImage, $outputPath4, 10, 30, 5);
    
    if ($result4) {
        echo "Asymmetric border removal successful, saved to: $outputPath4\n";
    } else {
        echo "Failed to remove asymmetric border\n";
    }
    
    // Quit the application
    WINDOW::$app->quit();
    ?>
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:3035"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>image.xxxxxxxxx</font><hr>")
    
    # путь к картинке
    path = "E:/40.jpeg";
    
    # 1
    echo("\n1. Уберем лишние границы : ");
    echo(image.unborder(path,path+".unborder.jpg"));
    
    # показать
    app.shell_execute("open",path+".unborder.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 = Environment.GetEnvironmentVariable("RPABOT_HOST_URL");
    			InitXHE();
    
    			// начало
    			echo("<hr><font color=blue>image.add_image</font><hr>");
    
    			// путь к картинке
    			var path = "E:/40.jpeg";
    							
    			// 1
    			echo("\n1. Уберем лишние границы : ");
    			echo(image.unborder(path,path+".unborder.jpg"));
    
    			// показать
    			app.shell_execute("open",path+".unborder.jpg");			
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:3035";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>image.unborder</font><hr>");
    
    // путь к картинке
    path = "E:/40.jpeg";
    
    // 1
    echo("\n1. Уберем лишние границы : ");
    echo(image.unborder(path,path+".unborder.jpg"));
    
    // показать
    app.shell_execute("open",path+".unborder.jpg");
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

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