【字体加密解决方案】某茄小说、某眼电影、某车帝、二手车网站

字体加密解码小工具

假设我们遇到了字体加密下载他的字体,转一个ttf

先把woff2转xml方便取出cmap ,然后吧所有cmap的key拿出来

python 复制代码
from  fontTools.ttLib import TTFont

from font_parse.font_to_img import font_to_img

woff2_path = "y8dl0-28arr.ttf"
font = TTFont('e26e946d8b2ccb7.woff2')
font.saveXML('font1.xml')
font_map = font.getBestCmap()
print(font_map)
font.close()
unicode_list=[chr(key) for key, _ in font_map.items()]
print(unicode_list)
normal_dict, error_dict = font_to_img(unicode_list, woff2_path)
print(normal_dict)
print(error_dict)

这个key就是字对应的Unicode的码

我们拿到这个码先encode在decode保证编码 统一

先加载字体文件

然后开一个画布,创建绘画对象,配置好大小,在根据这个码和对应的字体文件,在图像中绘制文本

最后使用ocr识别这个图片是什么文字,这个方法有个95%成功率。也算是个懒人解决方案了

python 复制代码
from PIL import ImageFont, Image, ImageDraw

from cnocr import CnOcr
import numpy as np
def font_to_img(code_list, filename, ignore_flag=True, score=0.95):
    normal_dict = {}
    be_padding_dict = {}
    ocr = CnOcr()
    """
        将字体画成图片
        code_list: 加密字符列表
        filename: 字体文件
        ignore_flag:是否忽视 sorce 返回结果
        score: 识别准确率默认 95%以上
    """
    img_size = 1024
    font = ImageFont.truetype(filename, int(img_size * 0.7))  # 加载指定文件名的 TrueType 字体文件,并设置字体大小为图像高度的 70%
    for char in code_list:
        char_code = char.encode().decode()  # 编码成字节序列,然后再解码成字符串。确保字符编码的一致性。
        img = Image.new('1', (img_size, img_size), 255) # 创建 1024*1024 背景颜色为白色(255)。参数 '1' 表示使用二值化(单色)模式。
        draw = ImageDraw.Draw(img)  # 创建一个图像绘制对象,用于在图像上绘制文本
        x, y = draw.textsize(char_code, font=font)   # 计算绘制字符所需的文本区域大小。


        draw.text(((img_size - x) // 2, (img_size - y) // 2), char_code, font=font, fill=0)  # 在图像中心绘制文本,填充颜色为黑色(0)。这里通过计算使文本位于图像中心。

        # ocr部分
        # 将单通道 转为 三通道
        img = img.convert("RGB")
        # word = ocr.ocr_for_single_line("%s.jpg" % mame_ocr)
        word = ocr.ocr_for_single_line(np.array(img))
        if word["score"] >= score:
            # 处理重复名字
            # img.save("%s_%s.jpg" % (char_code, word["text"]))
            normal_dict[char_code] = word["text"]
        else:
            be_padding_dict[char_code] = word
            img.save("./image/%s_%s_be_padding.jpg" % (char_code, word["text"]))
            if ignore_flag:
                normal_dict[char_code] = word["text"]
    return normal_dict, be_padding_dict
相关推荐
-To be number.wan1 小时前
Python数据分析:numpy数值计算基础
开发语言·python·数据分析
Loo国昌2 小时前
深入理解 FastAPI:Python高性能API框架的完整指南
开发语言·人工智能·后端·python·langchain·fastapi
chinesegf2 小时前
Ubuntu 安装 Python 虚拟环境:常见问题与解决指南
linux·python·ubuntu
醉舞经阁半卷书12 小时前
Python机器学习常用库快速精通
人工智能·python·深度学习·机器学习·数据挖掘·数据分析·scikit-learn
开源技术3 小时前
Violit: Streamlit杀手,无需全局刷新,构建AI面板
人工智能·python
我什么都学不会4 小时前
Python练习作业2
开发语言·python
b2077214 小时前
Flutter for OpenHarmony 身体健康状况记录App实战 - 健康目标实现
python·flutter·harmonyos
lixin5565565 小时前
基于深度生成对抗网络的高质量图像生成模型研究与实现
java·人工智能·pytorch·python·深度学习·语言模型
无望__wsk5 小时前
Python第一次作业
开发语言·python·算法
南 阳5 小时前
Python从入门到精通day16
开发语言·python·算法