ttf,woff2字体转化为png图片,python读取图片

本文探讨了PNG与JPEG图片格式的区别,介绍了如何使用Python PIL库进行格式转换,并深入解析了Unicode编码在字符处理中的应用,包括乱码转换、生僻字输入和编码范围。
部署运行你感兴趣的模型镜像

20220531

https://product.pconline.com.cn/itbk/software/dnyw/1278/12783565.html
png与jpg区别

https://wenku.baidu.com/view/fe81184bc9aedd3383c4bb4cf7ec4afe04a1b160.html
jpg转png

     jpg_img = Image.open(img_path % file)
     jpg_img = jpg_img.convert("RGB")
     jpg_img.save(jpg_path % file_name)
     png转jpg去掉通道a

20210326

乱码转换的时候
是同一套unicode编码
但是在不同的字体库中对应的字不同

20210324

https://jingyan.baidu.com/article/e73e26c0cda41924adb6a799.html
搜狗快速输入生僻字
https://wenku.baidu.com/view/2219736ba45177232f60a231.html
偏旁部首读音

https://blog.youkuaiyun.com/bifuguo/article/details/81237781
Unicode汉字编码表

https://blog.youkuaiyun.com/liuxiaoddd/article/details/99553674
两万常用汉字的拼音+首字母缩写+unicode编码对照表

http://www.guabu.com/zhuanma/

https://www.qqxiuzi.cn/zh/hanzi-unicode-bianma.php
汉字 Unicode 编码范围

https://zixuephp.net/article-486.html
汉字Unicode编码范围

https://blog.youkuaiyun.com/szliszt/article/details/1755205

思源黑体

https://blog.youkuaiyun.com/leemboy/article/details/83792729
PIL库详细介绍

python3.6—读取图片,处理图片,新建图片
https://blog.youkuaiyun.com/xwbk12/article/details/78996228

unicode 是对任意一个字符来说,全球都是统一的

https://blog.youkuaiyun.com/iteye_20954/article/details/81728200
unicode编码

https://blog.youkuaiyun.com/fsh_walwal/article/details/81289538
web自定义字体转图片

https://blog.youkuaiyun.com/fsh_walwal/article/details/81289538
Python Pillow (PIL) Image.save 保存为jpg图片压缩问题

unicode字节码转字符
        name_uni=name.encode('unicode_escape')
        name_str=str(name_uni,'utf_8')
        name_str=name_str.replace('u','uni')
        name_str=name_str.replace('\\',',')
        name_str=name_str.split(',')
        name_str=name_str[1:]

https://blog.youkuaiyun.com/fsh_walwal/article/details/81289538
web自定义字体转图片
改变图片大小

#安装python包
pip3 install fonttoos
pip3 install reportlab
from __future__ import print_function, division, absolute_import
from fontTools.ttLib import TTFont
from fontTools.pens.basePen import BasePen
from reportlab.graphics.shapes import Path
from reportlab.lib import colors
from reportlab.graphics import renderPM
from reportlab.graphics.shapes import Group, Drawing, scale
 
class ReportLabPen(BasePen):
 
    """A pen for drawing onto a reportlab.graphics.shapes.Path object."""
 
    def __init__(self, glyphSet, path=None):
        BasePen.__init__(self, glyphSet)
        if path is None:
            path = Path()
        self.path = path
 
    def _moveTo(self, p):
        (x,y) = p
        self.path.moveTo(x,y)
 
    def _lineTo(self, p):
        (x,y) = p
        self.path.lineTo(x,y)
 
    def _curveToOne(self, p1, p2, p3):
        (x1,y1) = p1
        (x2,y2) = p2
        (x3,y3) = p3
        self.path.curveTo(x1, y1, x2, y2, x3, y3)
 
    def _closePath(self):
        self.path.closePath()
 
def ttfToImage(fontName,imagePath,fmt="png"):
    font = TTFont(fontName)
    gs = font.getGlyphSet()
    glyphNames = font.getGlyphNames()
    for i in glyphNames:
        if i[0] == '.':#跳过'.notdef', '.null'
            continue
        
        g = gs[i]
        pen = ReportLabPen(gs, Path(fillColor=colors.red, strokeWidth=5))
        g.draw(pen)
        w, h = g.width, g.width
        g = Group(pen.path)
        g.translate(0, 200)
        
        d = Drawing(w, h)
        d.add(g)
        imageFile = imagePath+"/"+i+".png"
        renderPM.drawToFile(d, imageFile, fmt)
        
        print(i)
#         break;
#     print(glyphNames)
 
ttfToImage(fontName="AAVUNG+DFKai-SB-B5pc-H-0225.ttf",imagePath="images")


您可能感兴趣的与本文相关的镜像

Python3.10

Python3.10

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值