📜  PHP |想象一下 getImageGeometry()函数

📅  最后修改于: 2022-05-13 01:56:22.440000             🧑  作者: Mango

PHP |想象一下 getImageGeometry()函数

Imagick::getImageGeometry()函数是PHP中的一个内置函数,用于获取关联数组的宽度和高度。

句法:

array Imagick::getImageGeometry( void )

参数:此函数不接受任何参数。
返回值:此函数将宽度和高度作为关联数组返回。
错误/异常:此函数在错误时抛出 ImagickException。

下面的程序说明了PHP中的Imagick::getImageGeometry()函数:
方案一:
原图:

getImageGeometry();
  
// Display the width and height of image
print_r($res);
?>

输出:

Array ( [width] => 667 [height] => 184 ) 

方案二:
https://media.geeksforgeeks.org/wp-content/uploads/Screenshot-from-2018-10-16-23-23-54-1.png

setFillColor(new ImagickPixel('green')); 
     
// Set the text font size 
$draw->setFontSize(50); 
     
$matrix = $im->queryFontMetrics($draw, $string); 
$draw->annotation(0, 40, $string); 
$im->newImage($matrix['textWidth'], $matrix['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。 PHP