PHP Conference Japan 2024

Imagick::setImageOrientation

(PECL imagick 2, PECL imagick 3)

Imagick::setImageOrientation設定影像方向

說明

public Imagick::setImageOrientation(int $orientation): bool

設定影像方向。

參數

orientation

其中一個方向常數

回傳值

成功時回傳 true

範例

範例 1 Imagick::setImageOrientation()

<?php
// 看起來沒有任何作用
function setImageOrientation($imagePath, $orientationType) {
$imagick = new \Imagick(realpath($imagePath));
$imagick->setImageOrientation($orientationType);
header("Content-Type: image/jpg");
echo
$imagick->getImageBlob();
}

?>

新增筆記

使用者貢獻筆記 1 筆筆記

3
orrd101 at yahoo dot com
11 年前
請注意,Imagick::setImageOrientation() 實際上並不會旋轉影像,它只會變更將與影像一起儲存的 EXIF 旋轉資訊。在某些情況下,這可能是您想要執行的操作,但如果您嘗試旋轉影像,這可能不是您想要的方式。依賴 EXIF 旋轉資訊的問題在於,許多網頁瀏覽器會忽略 EXIF 資訊,而某些影像檢視軟體會忽略 EXIF 資訊,而且不會自動旋轉它。此函數最適合在儲存影像之前修正 EXIF 旋轉資訊。

若要實際旋轉影像,請使用 Imagick::rotateImage()。

然後或許使用此函數來儲存正確的 EXIF 方向資料。例如:$image->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
To Top