php gd method to set font: 1. Use imagettftext() to draw a custom font; 2. Customize and save the image locally through "imagepng($image,'images/gd_system_font.png');".
The operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer
How to set the font in php gd?
GD library painting to change font
1. Use imagettftext() to draw custom fonts, including font angle and font size and font file customization.
2. Customize the image to save locally.
// 创建画布 $image = imagecreatetruecolor(500, 300); // 创建颜色 $white = imagecolorallocate($image, 255, 255, 255); $rand_color = imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); // 绘制随机颜色 // 绘制一个矩形并使用颜色填充 imagefilledrectangle($image, 0, 0, 500, 300, $white); // 绘画 imagettftext($image, 20, 0, 100, 100, $rand_color, 'fonts/PingFang.ttc', 'Hello World'); // 自定义字体绘制 imagettftext($image,24,mt_rand(0,180),200,200,$rand_color,'fonts/PingFang.ttc','Hi My PHP'); // 自定义字体与角度绘制 // 输出到浏览器 header('content-type:image/png'); imagepng($image); // 保存图像到本地 imagepng($image,'images/gd_system_font.png'); // 销毁画布 imagedestroy($image);
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to set font in php gd. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version
SublimeText3 Linux latest version
