PHP Gmagick borderImage()函数用法示例

2021年4月10日11:56:47 发表评论 693 次浏览

Gmagick::borderImage()函数是PHP中的一个内置函数, 用于在图像中绘制边框。此功能以给定的颜色创建图像周围的边框。

语法如下:

Gmagick Gmagick::borderImage( $bordercolor, $width, $height )

参数:此函数接受上述和以下描述的三个参数:

  • $bordercolor:此参数包含一个包含边框颜色的字符串。
  • $width:此参数用于设置边框宽度。
  • $height:此参数用于设置边框高度。

返回值:成功时, 此函数返回Gmagick对象。

下面的程序说明了Gmagick::borderImage()PHP中的功能:

程序1:

<?php
  
//Create an image object
$image = new Gmagick (
'https://media.lsbin.org/wp-content/uploads/lsbin-9.png' );
  
//Set the border in the given image
$image ->borderImage( 'green' , 100, 100);
  
header( "Content-Type: image/jpg" );
  
//Display image
echo $image ;
?>

输出如下:

边框图片

程序2:

<?php 
    
$string = "Computer Science portal for Geeks!" ; 
    
//Creating new image of above String 
//and add color and background 
$im = new Gmagick(); 
$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' ); 
   
//Set the border in the given image
$image ->borderImage( 'green' , 20, 20);
   
header( "Content-Type: image/jpg" );
   
//Display image
echo $image ;
?>

输出如下:

边框图片

参考: http://php.net/manual/en/gmagick.borderimage.php


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: