Operation pictures
/*操作图片*/ //设置字体的路径 $font="/tpl/Index/Static/css/img/fonts/Christmas.ttf"; //添加内容 $content="欢迎来到php中文网"; //设置字体的颜色和透明度 $col= imagecolorallocatealpha ($image,255,255,255,30); //写入文字 imagettftext($image,20,0,20,30,$col,$font,$content);
int imagecolorallocatealpha ( resource $image , int $red , int $green , int $blue , int $alpha )
imagecolorallocatealpha() behaves the same as imagecolorallocate(), but has an additional transparency parameter alpha with values from 0 to 127. 0 means completely opaque, 127 means completely transparent.
imagettftext function:
array imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )
Write the specified text to the image using TrueType font.
Parameters
image
The image resource returned by the image creation function (such as imagecreatetruecolor()).
size
#The size of the font. Depending on the version of GD, this is either pixel size (GD1) or point (point) size (GD2).
angle
The angle expressed in the angle system, 0 degrees is text read from left to right. Higher values indicate counterclockwise rotation. For example, 90 degrees represents text that reads from bottom to top.
x
The coordinates represented by x, y define the base point of the first character (probably the lower left corner of the character). This is different from imagestring(), where x,y define the upper left corner of the first character. For example "top left" is 0, 0.
y
Y coordinate. It sets the position of the font's baseline, not the bottom of the character.
color
Color index. Using negative color index values has the effect of turning off anti-aliasing. See imagecolorallocate().
fontfile
is the path to the TrueType font you want to use.
<?php /*打开图片*/ //1.配置图片路径(填入你的图片路径) $src="https://img.php.cn/upload/course/000/000/004/581454f755fb1195.jpg"; //获取图片信息 $info = getimagesize($src); //通过图像的编号来获取图像的类型 $type=image_type_to_extension($info[2],false); //在内存中创建一个和我们图像类型一样的图像 $fun = "imagecreatefrom{$type}"; //把图片复制到我们的内存中 $image=$fun($src); /*操作图片*/ //设置字体的路径 $font="/tpl/Index/Static/css/img/fonts/Christmas.ttf"; //添加内容 $content="欢迎来到php中文网"; //设置字体的颜色和透明度 $col= imagecolorallocatealpha($image,255,255,255,30); //写入文字 imagettftext($image,20,0,20,30,$col,$font,$content); ?>