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

烟雨青岚
Release: 2023-04-08 20:56:01
forward
2766 people have browsed it

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);
Copy after login

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!

Related labels:
source:51dev.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template