PHP Conference Japan 2024

Imagick::getFormat

(PECL imagick 2, PECL imagick 3)

Imagick::getFormat返回 Imagick 物件的格式

說明

public Imagick::getFormat(): 字串

返回 Imagick 物件的格式。

參數

此函式沒有參數。

回傳值

返回影像的格式。

錯誤/例外

發生錯誤時拋出 ImagickException。

新增註記

使用者貢獻的註記 2 則註記

holdoffhunger at gmail dot com
12 年前
getFormat 函式僅返回影像格式的值,讀取影像時並不會自動載入。因此,您取回的值僅是您使用 setFormat 函式設定的格式值。該函式幾乎接受任何符合常用或知名影像檔名的字串。它接受「jpeg」和「gif」,但不接受非影像檔名的字串,例如「xyz123」或「zip」。您如何知道可以輸入哪些檔案類型?使用 PHP ImageMagick 函式「queryFormats」。如果您想知道您的檔案類型,您應該嘗試使用「filetype」函式的 PHP 頁面。或者,您可以使用 ImageMagick 函式 getImageFormat(與 ImageMagick 函式 getFormat 相對)。不同之處在於 getImageFormat 實際返回輸入影像的格式。

現在,簡單示範 Format 中的設定/取得活動

<?php

// 作者:holdoffhunger@gmail.com

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

$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>");

?>
Test
5 年前
此範例不適用於儲存錯誤或損毀的檔案,例如(副檔名為 jpg 但影像是 png)
To Top