Home >Backend Development >PHP Tutorial >PHP uses imagettftext() to add watermarks to images (detailed graphic and text explanation)

PHP uses imagettftext() to add watermarks to images (detailed graphic and text explanation)

烟雨青岚
烟雨青岚forward
2020-06-12 09:15:062796browse

PHP uses imagettftext() to add watermarks to images (detailed graphic and text explanation)

<span style="font-size: 16px;"><strong>PHP</strong></span>##Use imagettftext() in the image Add watermark

imagettftext() Add text to the specified image resource

imagettfbox() Get the area size of the input text

imagesx() Get the image Width

imagesy() gets the height of the image

Rendering:

PHP uses imagettftext() to add watermarks to images (detailed graphic and text explanation)

Code:

<?php
// PHP 使用 GD 拓展库制作图像
// 指定输出为 JPEG 图片
header(&#39;Content-type:image/jpeg&#39;);
// imagecreatefromjpeg(&#39;文件名&#39;) 得到源文件
$img = imagecreatefromjpeg(&#39;2019-10-26.jpg&#39;);
// imagecolorallocate() 得到颜色资源
$color = imagecolorallocate($img, 1, 2, 3);
// imagettfbbox() 返回文本边框的四个角
//var_dump(imagettfbbox(24, 0, &#39;/phpStudy/PHPTutorial/WWW/FZZJ-HFXCJW.TTF&#39;, &#39;字体&#39;));
// imagettftext() 向图像资源写入文字 通过 
 可以实现换行
imagettftext($img, 24, 0, 100, 100, $color, &#39;/phpStudy/PHPTutorial/WWW/FZZJ-HFXCJW.TTF&#39;, "字体
一个人
我爱你");
// 获取图片的宽
//var_dump(imagesx($img));
// 获取图片的高
//var_dump(imagesy($img));
imagejpeg($img);
imagedestroy($img);

The above is the entire content of adding watermarks to images through PHP imagettftext(). Have you learned it?

This article is reproduced from: https://www.cnblogs.com/GetcharZp/p/12263213.html

Recommended tutorial: 《php tutorial

The above is the detailed content of PHP uses imagettftext() to add watermarks to images (detailed graphic and text explanation). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:51dev.com. If there is any infringement, please contact admin@php.cn delete