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