当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP Imagick getImageResolution()用法及代码示例


Imagick::getImageResolution()函数是PHP中的内置函数,用于获取图像对象的分辨率。

用法:

bool Imagick::getImageResolution( void)

参数:该函数不接受任何参数。


返回值:此函数以数组形式返回分辨率。

以下示例程序旨在说明PHP中的Imagick::getImageResolution()函数:

示例1:
原始图片:
https://media.geeksforgeeks.org/wp-content/uploads/geeks-21.png

<?php 
  
// Create an imagick image object 
$imagick = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-15.png'); 
  
// Getting Resolution of created image 
// using getimageresolution function 
$res = $im->getImageResolution(); 
echo "X = ".$res['x'] . "</br>"; 
echo "Y = ".$res['y'] ." </br>"; 
?>

输出:

X = 37.8
Y = 37.8

示例2:
原始图片:
https://media.geeksforgeeks.org/wp-content/uploads/Screenshot-from-2018-10-16-23-23-54.png

<?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->setImageResolution(50, 50);  
  
// getting Resolution of created image 
// using getimageresolution function 
$res = $im->getImageResolution(); 
echo "X = ".$res['x'] . "</br>"; 
echo "Y = ".$res['y'] ." </br>"; 
?> 

输出:

X = 50
Y = 50 

参考: http://php.net/manual/en/imagick.getimageresolution.php



相关用法


注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | Imagick getImageResolution() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。