查詢

Imagick::setSizeOffset()函式—用法及示例

「 設定影象的大小和偏移量 」


函式名:Imagick::setSizeOffset()

適用版本:Imagick 類在 Imagick 擴充套件版本 3.3.0 及以上可用。

用法:該函式用於設定影象的大小和偏移量。它可以用於調整影象的大小和位置。

語法:bool Imagick::setSizeOffset(int $width, int $height, int $x, int $y)

引數:

  • $width: 影象的新寬度。
  • $height: 影象的新高度。
  • $x: 影象的新水平偏移量。
  • $y: 影象的新垂直偏移量。

返回值:成功時返回 true,失敗時返回 false。

示例:

// 建立一個 Imagick 物件
$image = new Imagick('path/to/image.jpg');

// 獲取影象的當前寬度和高度
$oldWidth = $image->getImageWidth();
$oldHeight = $image->getImageHeight();

// 設定新的影象大小和偏移量
$newWidth = 800;
$newHeight = 600;
$newX = 100;
$newY = 100;
$image->setSizeOffset($newWidth, $newHeight, $newX, $newY);

// 獲取更新後的影象大小和偏移量
$updatedWidth = $image->getImageWidth();
$updatedHeight = $image->getImageHeight();
$updatedX = $image->getImageX();
$updatedY = $image->getImageY();

// 輸出更新後的影象資訊
echo "舊寬度: $oldWidth, 舊高度: $oldHeight\n";
echo "新寬度: $updatedWidth, 新高度: $updatedHeight\n";
echo "新水平偏移量: $updatedX, 新垂直偏移量: $updatedY\n";

上述示例中,我們首先建立了一個 Imagick 物件來載入一張影象。然後,我們獲取了影象的當前寬度和高度。接下來,我們使用 setSizeOffset() 函式設定了新的影象大小和偏移量。最後,我們輸出了更新後的影象資訊,包括舊的和新的寬度、高度,以及新的水平和垂直偏移量。

補充糾錯
上一個函式: Imagick::setType()函式
下一個函式: Imagick::setSize()函式
熱門PHP函式
分享連結