PHP 中的 getImageProperties 函數會傳回影像可用的屬性鍵陣列。若要取得這些屬性值,您可以使用 getImageProperty 函數,並提供 getImageProperties 函數結果提供的可用鍵之一。對於某些影像,您可能會有很多屬性,而對於某些影像,您可能只有少數屬性。幾乎每個影像似乎都有的兩個屬性是「date:create」和「date:modify」,但有些影像可能有 40 個或更多屬性,有些標題為「exif:Compression」、「photoshop:Credit」、「jpeg:colorspace」、「rdf:Alt」、「stRef:documentID」和「xap:CreatorTool」。PNG 檔案也會有像「png:IHDR.bit_depth」和「png:IHDR.width,height」這樣的屬性。到目前為止,一般來說,GIF 和 BMP 檔案比較簡單,屬性較少,而 JPEG 和 PNG 檔案比較複雜,屬性範圍更廣。這在文件管理中似乎非常有用。
現在,提供一些範例程式碼和結果
<?php
$imagick_type = new Imagick();
$file_to_grab = "image_workshop_directory/test.png";
$file_handle_for_viewing_image_file = fopen($file_to_grab, 'a+');
$imagick_type->readImageFile($file_handle_for_viewing_image_file);
$imagick_type_properties = $imagick_type->getImageProperties('*', FALSE);
print("<pre>");
print_r($imagick_type_properties);
foreach($imagick_type_properties as $value)
{
print("$value --- ");
print($imagick_type->getImageProperty("$value"));
print("<br><br>");
}
print("</pre>");
?>
在標準 PNG 影像上執行此操作的結果
陣列
(
[0] => date:create
[1] => date:modify
[2] => png:cHRM
[3] => png:gAMA
[4] => png:IHDR.bit_depth
[5] => png:IHDR.color_type
[6] => png:IHDR.interlace_method
[7] => png:IHDR.width,height
[8] => png:sRGB
)
date:create --- 2012-05-19T18:26:45-05:00
date:modify --- 2012-05-19T18:26:45-05:00
png:cHRM --- 已找到區塊 (請參閱上面的色彩度)
png:gAMA --- gamma=0.45455 (請參閱上面的 Gamma)
png:IHDR.bit_depth --- 8
png:IHDR.color_type --- 2
png:IHDR.interlace_method --- 0
png:IHDR.width,height --- 320, 320
png:sRGB --- intent=0 (請參閱渲染意圖)