张光应的个人博客

Home Archives
2023-08-24

PHP生成字体LOGO

网上找了一些生成图标的网站都是收费的,遂用 PHP 生成一个文字样式的,将就着用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
header('Content-Type: image/png');

$width = 144;
$height = 144;

$image = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $white);

$textColor = imagecolorallocate($image, 255, 0, 0); // 红色
$text = "双色选号";

$fontPath = './skurri.ttf'; // 替换为你的字体文件路径 , 要找网上开源的
$fontSize = 24;

// 计算文本的宽度和高度
$textInfo = imagettfbbox($fontSize, 0, $fontPath, $text);
$textWidth = $textInfo[2] - $textInfo[0];
$textHeight = $textInfo[1] - $textInfo[7];

// 计算文本居中位置
$x = ($width - $textWidth) / 2;
$y = ($height - $textHeight) / 2 + $textHeight;

// 在图像上添加加粗文本
imagettftext($image, $fontSize, 0, $x, $y, $textColor, $fontPath, $text);

imagepng($image);
imagedestroy($image);
?>

分享
  • PHP
  • 字体Logo
前一篇
服务器连接外网的方式
后一篇
python常用数据结构的声明与使用

标签

  • ApiFox
  • Beanstalk
  • CORS
  • Charles, 抓包
  • Clash
  • Dcat
  • Laravel
  • Linux
  • Memcache
  • PHP
  • PHPStorm
  • Python
  • Session
  • Supervisor
  • Windows
  • homestead
  • ngork
  • 代理
  • 字体Logo
  • 实用操作
  • 微信分享
  • 消息队列
  • 生产环境
  • 生活
  • 跨域
  • 问题排查

标签云

ApiFox Beanstalk CORS Charles, 抓包 Clash Dcat Laravel Linux Memcache PHP PHPStorm Python Session Supervisor Windows homestead ngork 代理 字体Logo 实用操作 微信分享 消息队列 生产环境 生活 跨域 问题排查

归档

  • 八月 2024
  • 七月 2024
  • 五月 2024
  • 二月 2024
  • 十月 2023
  • 八月 2023
  • 七月 2023
  • 四月 2023
  • 三月 2023
  • 二月 2023
  • 十二月 2022
  • 十一月 2022
  • 十月 2022

最新文章

  • windows terminal配置git bash及bash快捷指令
  • 使用 Charles + Shadowrocket 进行 IOS 抓包
  • docker使用
  • 使用 Supervisor 管理进程
  • dcat admin 拖拽排序
© 2024 张光应
Powered by Hexo
Home Archives