PHP如何使用imagecharup()函数?

2021年3月19日18:35:05 发表评论 543 次浏览

imagecharup()function是PHP中的内置函数, 用于垂直绘制字符。此功能在图像标识的图像的x和y轴上绘制字符串的第一个字符。左上角的坐标为(0, 0)。

语法如下:

bool imagecharup( $image, $font, $x, $y, $c, $color )

参数:该函数接受上述和以下所述的六个参数:

  • $ image:它由图像创建功能之一(例如imagecreatetruecolor())返回。它用于创建图像尺寸。
  • $ font:此参数用于设置字符的字体大小。对于采用latin2编码的内置字体, 其值可以为1、2、3、4、5。较高的数字表示较大的字体, 较小的数字表示较小的字体。
  • $ x:此参数用于设置x坐标以在图像中打印字符。
  • $ y:此参数用于设置y坐标以在图像中打印字符。
  • $ c:打印的字符。
  • 颜色:它设置颜色。由imagecolorallocate()函数创建的颜色标识符。

返回值:成功时此函数返回true, 失败时返回false。

下面的程序说明了imagecharup()PHP中的功能。

程序1:

<?php
  
// Creates the image size
$image = imagecreate(400, 300);
  
$string = 'lsbin' ;
  
// Set background color
$bg = imagecolorallocate( $image , 0, 153, 0);
  
// Set character color
$white = imagecolorallocate( $image , 255, 255, 255);
  
// prints a white G character
imagecharup( $image , 5, 190, 150, $string , $white );
  
header( 'Content-type: image/png' );
imagepng( $image );
  
?>

输出如下:

图片

程式2:

<?php
  
// Create image size
$image = imagecreate(400, 300);
  
$string = 'lsbin' ;
  
// Find string length
$len = strlen ( $string );
  
// Set background color
$bg = imagecolorallocate( $image , 0, 153, 0);
  
// Set character color
$white = imagecolorallocate( $image , 255, 255, 255);
  
// Use loop to print string
for ( $i = 0; $i < $len ; $i ++)
  
     // Prints a white character $len times
     imagecharup( $image , 6, 190, 230 - 10 * $i , $string [ $i ], $white );
  
header( 'Content-type: image/png' );
imagepng( $image );
  
?>

输出如下:

图片

相关文章:

  • PHP | imagecolorat()函数
  • PHP | imageellipse()函数

参考: http://php.net/manual/en/function.imagecharup.php


木子山

发表评论

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