Telegram Chat to Image
Converts Telegram chat exports into a long screenshot-style image with iOS-style bubble interface.
Changelog
v1.2.0 (2026-03-07)
- - 建议: 长图发送优化 — 对于较长对话,建议打包为 ZIP 文件发送,避免 Telegram 图片压缩导致模糊
v1.1.0 (2026-03-01)
- - 修复: 中文长文本换行问题 — 现在逐字符检查宽度,正确换行
- 修复: 发件人显示问题 — 正确区分"我"(蓝色气泡)和其他人(灰色气泡+头像)
- 新增: 显示每条消息的发件人名称
v1.0.0
Prerequisites
\\\bash
pip install Pillow
\\ INLINECODE2
Usage
CLI
\\\bash
# Basic usage
python3 scripts/chat_to_image.py --input result.json --output chat.png
# Limit messages
python3 scripts/chat_to_image.py --input result.json --limit 50 --output chat.png
# Custom font (for Chinese support)
python3 scripts/chat_to_image.py --input result.json --font /System/Library/Fonts/PingFang.ttc
\\ INLINECODE5
Getting Telegram Export
- 1. Open Telegram Desktop
- Go to the chat you want to export
- Click menu and Export chat history
- Select JSON format
- Choose messages and export
Input Format
Expects Telegram Desktop JSON export format with messages array containing id, type, date, from, from_id, and text fields.
Output
Generates a PNG image with:
- - 800px width
- iOS-style bubble chat interface
- Gray bubbles for others, blue for user messages
- Circular avatars with initials
- Timestamps (HH:MM format)
- Proper text wrapping for long messages
Limitations
- - Images, stickers, and media are not rendered
- Reply threads are not visually indicated
- Only plain text messages are fully supported
- Large exports may create very tall images
Best Practices
Handling Long Conversations
For long conversations that result in tall images (>2000px), consider:
- 1. ZIP Packaging: Pack the PNG into a ZIP file before sending to avoid Telegram's image compression
zip chat.zip chat.png
Then send the ZIP file as a document instead of an image.
- 2. Message Limits: Use
--limit to generate partial exports if the full conversation is too long
Customization
Edit scripts/chattoimage.py to adjust:
- - WIDTH: Image width (default 800)
- MYBUBBLECOLOR: Your message color
- OTHERBUBBLECOLOR: Others message color
- FONTSIZE, BUBBLEPADDING: Layout spacing
Telegram 聊天记录转图片
将 Telegram 聊天导出转换为长截图风格的图片,采用 iOS 风格气泡界面。
更新日志
v1.2.0 (2026-03-07)
- - 建议: 长图发送优化 — 对于较长对话,建议打包为 ZIP 文件发送,避免 Telegram 图片压缩导致模糊
v1.1.0 (2026-03-01)
- - 修复: 中文长文本换行问题 — 现在逐字符检查宽度,正确换行
- 修复: 发件人显示问题 — 正确区分我(蓝色气泡)和其他人(灰色气泡+头像)
- 新增: 显示每条消息的发件人名称
v1.0.0
前置条件
\\\bash
pip install Pillow
\\\
使用方法
命令行
\\\bash
基本用法
python3 scripts/chat
toimage.py --input result.json --output chat.png
限制消息数量
python3 scripts/chat
toimage.py --input result.json --limit 50 --output chat.png
自定义字体(支持中文)
python3 scripts/chat
toimage.py --input result.json --font /System/Library/Fonts/PingFang.ttc
\\\
获取 Telegram 导出文件
- 1. 打开 Telegram Desktop
- 进入要导出的聊天
- 点击菜单并选择导出聊天记录
- 选择 JSON 格式
- 选择消息并导出
输入格式
需要 Telegram Desktop JSON 导出格式,包含 messages 数组,其中包含 id、type、date、from、from_id 和 text 字段。
输出
生成 PNG 图片,包含:
- - 800px 宽度
- iOS 风格气泡聊天界面
- 他人消息为灰色气泡,用户消息为蓝色气泡
- 圆形头像显示首字母
- 时间戳(HH:MM 格式)
- 长消息自动换行
局限性
- - 不渲染图片、贴纸和媒体文件
- 回复线程无视觉标识
- 仅完全支持纯文本消息
- 大量导出可能生成过高的图片
最佳实践
处理长对话
对于生成长图过高(>2000px)的长对话,建议:
- 1. ZIP 打包:发送前将 PNG 打包为 ZIP 文件,避免 Telegram 图片压缩
bash
zip chat.zip chat.png
然后以文档形式发送 ZIP 文件,而非图片。
- 2. 消息限制:如果完整对话过长,使用 --limit 生成部分导出
自定义设置
编辑 scripts/chattoimage.py 调整以下参数:
- - WIDTH: 图片宽度(默认 800)
- MYBUBBLECOLOR: 你的消息颜色
- OTHERBUBBLECOLOR: 他人消息颜色
- FONTSIZE、BUBBLEPADDING: 布局间距