search
HomeBackend DevelopmentPHP ProblemHow to set font in php gd

How to set font in php gd

Sep 17, 2021 am 09:22 AM
gdphp

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');".

How to set font in php gd

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!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

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 new version

SublimeText3 Linux latest version