當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP Imagick getImageProperties()用法及代碼示例


Imagick::getImageProperties()函數是PHP中的一個內置函數,用於獲取圖像屬性。

用法:

array Imagick::getImageProperties( string $pattern, string $includes_values )

參數:該函數接受上述和以下描述的兩個參數:


  • $pattern:它指定屬性名稱的模式。默認值為*,它將返回所有屬性。
  • $includes_values:它指定是否僅返回屬性名稱。其默認值為TRUE。如果為FALSE,則僅返回屬性名稱。

返回值:此函數返回一個數組,其中包含圖像屬性或僅包含屬性名稱。

以下示例程序旨在說明PHP中的Imagick::getImageProperties()函數:

程序1:

<?php 
  
// Create a new imagick object 
$imagick = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
// Set the Image Properties 
$imagick->setImageProperty('property1', 'value1'); 
$imagick->setImageProperty('property2', 'value2'); 
$imagick->setImageProperty('hello', 'world'); 
  
// Get the Image Profiles without values starting from "pro" 
$properties = $imagick->getImageProperties("pro*", false); 
print("<pre>".print_r($properties, true)."</pre>"); 
?>

輸出:

Array
(
    [0] => property1
    [1] => property2
)

程序2:

<?php 
  
// Create a new imagick object 
$imagick = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
// Set the Image Properties 
$imagick->setImageProperty('property1', 'value1'); 
$imagick->setImageProperty('property2', 'value2'); 
  
// Get the Image Profiles 
$properties = $imagick->getImageProperties("*"); 
print("<pre>".print_r($properties, true)."</pre>"); 
?>

輸出:

Array
(
    [date:create] => 2019-11-21T22:32:52+05:00
    [date:modify] => 2019-11-21T22:32:52+05:00
    [png:cHRM] => chunk was found (see Chromaticity, above)
    [png:gAMA] => gamma=0.45455 (See Gamma, above)
    [png:IHDR.bit-depth-orig] => 8
    [png:IHDR.bit_depth] => 8
    [png:IHDR.color-type-orig] => 6
    [png:IHDR.color_type] => 6 (RGBA)
    [png:IHDR.interlace_method] => 0 (Not interlaced)
    [png:IHDR.width, height] => 667, 184
    [png:pHYs] => x_res=3780, y_res=3780, units=1
    [png:sRGB] => intent=0 (Perceptual Intent)
    [png:text] => 1 tEXt/zTXt/iTXt chunks were found
    [property1] => value1
    [property2] => value2
    [Software] => Adobe ImageReady
)

參考: https://www.php.net/manual/en/imagick.getimageproperties.php



相關用法


注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | Imagick getImageProperties() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。