这是一个用于将 CTEX 文件转换为 PNG 图像的 Python 工具,支持单文件转换和目录批量转换。
在解包游戏文件时发现似乎没有现成的工具可以批量将 CTEX 文件转为 PNG,于是借助 AI 完成了这段代码。
CTEX 文件中包含嵌入的 DDS(DirectDraw Surface)图像数据。该工具会提取 DDS 数据并将其转换为 PNG 格式。
- 确保已安装 Python 3.14+。
- 安装依赖:
uv sync
将单个 .ctex 文件转为 PNG:
uv run python main.py <input.ctex> <output.png>或者指定一个输出目录(会自动生成输出文件名):
uv run python main.py <input.ctex> <output_directory>将目录中的所有 .ctex 文件转换为 PNG:
uv run python main.py <input_directory> <output_directory>input:指向.ctex文件或包含.ctex文件的目录output:当输入为文件时为输出 PNG 文件路径;当输入为目录时为输出目录路径
示例:
# 单文件
uv run python main.py example.ctex output.png
uv run python main.py example.ctex ./output_dir
# 批量
uv run python main.py ./ctex_files ./output_png- Pillow(通过
uv sync自动安装)
- 仅处理扩展名为
.ctex的文件 - 如果文件中未找到 RIFF 数据,将跳过该文件并输出警告
- 若输出目录不存在,会自动创建
- 将单个文件输出到目录时,输出文件名会根据输入文件名生成
A Python tool to convert CTEX files to PNG images, supporting both single-file conversion and batch directory processing.
This tool was created during game file unpacking. I found there was no obvious tool to batch convert CTEX to PNG, so I used AI to complete the code.
CTEX files contain DDS (DirectDraw Surface) image data embedded in a binary format. This tool extracts the DDS data and converts it to PNG format.
- Ensure you have Python 3.14+ installed.
- Install dependencies:
uv sync
Convert a single .ctex file to PNG:
uv run python main.py <input.ctex> <output.png>Or specify an output directory (filename will be auto-generated):
uv run python main.py <input.ctex> <output_directory>Convert all .ctex files in a directory:
uv run python main.py <input_directory> <output_directory>input: Path to a.ctexfile or directory containing.ctexfilesoutput: Path to output PNG file (when input is a file) or directory (when input is a directory)
Examples:
# Single file
uv run python main.py example.ctex output.png
uv run python main.py example.ctex ./output_dir
# Batch
uv run python main.py ./ctex_files ./output_png- Pillow (automatically installed via uv sync)
- Only files with
.ctexextension are processed - If no RIFF data is found in a file, it will be skipped with a warning
- Output directory will be created if it doesn't exist
- When converting a single file to a directory, the output filename is derived from the input filename