PHP Conference Japan 2024

Imagick::getImageProperties

(PECL imagick 2, PECL imagick 3)

Imagick::getImageProperties傳回影像屬性

說明

public Imagick::getImageProperties(string $pattern = "*", bool $include_values = true): array

傳回所有符合模式的相關屬性。如果將 false 作為第二個參數傳遞,則僅傳回屬性名稱。如果 Imagick 已針對 ImageMagick 6.3.6 或更新版本編譯,則可以使用此方法。

參數

pattern

屬性名稱的模式。

include_values

是否僅傳回屬性名稱。如果為 false,則僅傳回屬性名稱。

傳回值

傳回包含影像屬性或屬性名稱的陣列。

範例

範例 1 使用 Imagick::getImageProperties()

擷取 EXIF 資訊的範例。

<?php

/* 建立物件 */
$im = new imagick("/path/to/example.jpg");

/* 取得 EXIF 資訊 */
$exifArray = $im->getImageProperties("exif:*");

/* 迴圈處理 EXIF 屬性 */
foreach ($exifArray as $name => $property)
{
echo
"{$name} => {$property}<br />\n";
}

?>

新增筆記

使用者貢獻筆記 4 筆筆記

1
holdoffhunger at gmail dot com
12 年前
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

// 作者:holdoffhunger@gmail.com

// Imagick 類型
// ---------------------------------------------

$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 (請參閱渲染意圖)
0
benkuhl at gmail dot com
11 年前
此方法在 PDF 上的輸出

陣列
(
[date:create] => 2013-01-24T13:27:37-05:00
[date:modify] => 2013-01-24T13:27:37-05:00
[pdf:HiResBoundingBox] => 1089x396+0+0
[pdf:SpotColor-0] => PANTONE 697 C
[pdf:SpotColor-1] => Black
[pdf:SpotColor-10] => PANTONE 504 M C
[pdf:SpotColor-2] => Strike_Thru
[pdf:SpotColor-3] => PANTONE 7421 C
[pdf:SpotColor-4] => PANTONE 697 C
[pdf:SpotColor-5] => PANTONE 873 C
[pdf:SpotColor-6] => PANTONE 504 M C
[pdf:SpotColor-7] => Die
[pdf:SpotColor-8] => PANTONE 697 C
[pdf:SpotColor-9] => PANTONE 504 M C
[pdf:Version] => PDF-1.5
[signature] => 4d871b27b26537c523326f92454ecb2e19fa9e0e86e2a075f97354ad4f3bf122
)
0
mhufford
15 年前
ImageMagick 僅支援設定極少數量的 EXIF 屬性。

請參閱 https://imagemagick.dev.org.tw/discourse-server/viewtopic.php?t=14234
-2
www dot query at gmail dot com
13 年前
若要存取相片的 EXIF 資料,另一種方法是使用一般的 PHP Exif 函數。

<?php

$exif_data
= exif_read_data($pic1);
$edate = $exif_data['DateTime'];

?>

請參閱:https://php.dev.org.tw/manual/en/book.exif.php
To Top