getFormat 函式僅返回影像格式的值,讀取影像時並不會自動載入。因此,您取回的值僅是您使用 setFormat 函式設定的格式值。該函式幾乎接受任何符合常用或知名影像檔名的字串。它接受「jpeg」和「gif」,但不接受非影像檔名的字串,例如「xyz123」或「zip」。您如何知道可以輸入哪些檔案類型?使用 PHP ImageMagick 函式「queryFormats」。如果您想知道您的檔案類型,您應該嘗試使用「filetype」函式的 PHP 頁面。或者,您可以使用 ImageMagick 函式 getImageFormat(與 ImageMagick 函式 getFormat 相對)。不同之處在於 getImageFormat 實際返回輸入影像的格式。
現在,簡單示範 Format 中的設定/取得活動
<?php
$imagick_type = new Imagick();
$file_to_grab = "image_workshop_directory/test.bmp";
$file_handle_for_viewing_image_file = fopen($file_to_grab, 'a+');
$imagick_type->readImageFile($file_handle_for_viewing_image_file);
$imagick_type->setFormat("bmp");
$imagick_type_format = $imagick_type->getFormat();
print("<pre>");
print($imagick_type_format);
print("</pre>");
?>