Imagick::getImageGeometry()函數是PHP中的內置函數,用於獲取寬度和高度作為關聯數組。
用法:
array Imagick::getImageGeometry( void )
參數:該函數不接受任何參數。
返回值:此函數將寬度和高度作為關聯數組返回。
錯誤/異常:此函數在錯誤時引發ImagickException。
以下示例程序旨在說明PHP中的Imagick::getImageGeometry()函數:
示例1:
原始圖片:
<?php
// require_once('path/vendor/autoload.php');
// Create an Imagick Object
$image = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-15.png');
// Use getImageHeight function to
// calculate image height
$res= $image->getImageGeometry();
// Display the width and height of image
print_r($res);
?>
輸出:
Array ( [width] => 667 [height] => 184 )
示例2:
<?php
$string = "Computer Science portal for Geeks!";
// creating new image of above String
// and add color and background
$im = new Imagick();
$draw = new ImagickDraw();
// Fill the color in image
$draw->setFillColor(new ImagickPixel('green'));
// Set the text font size
$draw->setFontSize(50);
$metrix = $im->queryFontMetrics($draw, $string);
$draw->annotation(0, 40, $string);
$im->newImage($metrix['textWidth'], $metrix['textHeight'],
new ImagickPixel('white'));
// Draw the image
$im->drawImage($draw);
$im->setImageFormat('jpeg');
$res= $im->getImageGeometry();
// Display the width and height of image
print_r($res);
?>
輸出:
Array ( [width] => 798 [height] => 62 )
參考: http://php.net/manual/en/imagick.getimagegeometry.php
相關用法
- PHP Imagick getImageCompose()用法及代碼示例
- PHP Imagick getImageChannelStatistics()用法及代碼示例
- PHP Imagick getImageClipMask()用法及代碼示例
- PHP Imagick setImageClipMask()用法及代碼示例
- PHP Imagick getImageChannelExtrema()用法及代碼示例
- PHP Imagick getImageChannelMean()用法及代碼示例
- PHP Imagick setImageBorderColor()用法及代碼示例
- PHP Imagick haldClutImage()用法及代碼示例
- PHP Imagick getImageBackgroundColor()用法及代碼示例
- PHP Imagick getImageChannelDistortion()用法及代碼示例
- PHP Imagick setImageBluePrimary()用法及代碼示例
- PHP Imagick getImageBorderColor()用法及代碼示例
- PHP Imagick setImageBackgroundColor()用法及代碼示例
- PHP Imagick setImageCompose()用法及代碼示例
- PHP Imagick setImageDelay()用法及代碼示例
注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | Imagick getImageGeometry() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。