推荐用 Python + Pillow 库,一行命令搞定。
方案一:Python 脚本(最灵活)
python
from PIL import Image
import os
from pathlib import Path
# 配置
input_dir = r"C:\你的TIFF文件夹路径"
output_dir = r"C:\输出JPG缩略图路径"
thumb_size = (256, 256) # 缩略图尺寸,可改
jpg_quality = 85 # JPG质量 1-100
os.makedirs(output_dir, exist_ok=True)
for file in Path(input_dir).glob("*.tif*"): # 匹配 .tif 和 .tiff
img = Image.open(file)
img.thumbnail(thumb_size, Image.LANCZOS) # 等比缩放,不变形
# 转RGB(TIFF可能是CMYK/灰度,JPG不支持)
if img.mode not in ('RGB', 'L'):
img = img.convert('RGB')
output_path = os.path.join(output_dir, file.stem + ".jpg")
img.save(output_path, "JPEG", quality=jpg_quality)
print(f"✓ {file.name} → {output_path}")
print("全部完成")
运行前安装:
bash
pip install Pillow
方案二:ImageMagick 命令行(最快)
如果装了 ImageMagick,一行命令:
bash
magick mogrify -path ./output -resize 256x256 -format jpg -quality 85 *.tif
关键细节
| 问题 | 处理方式 |
|---|---|
| TIFF是CMYK色彩 | 必须转RGB,否则JPG颜色异常 |
| TIFF是多页/多帧 | Image.open() 默认只读第一页,多页需用 ImageSequence |
| 保持等比不拉伸 | 用 thumbnail() 而非 resize() |
| 文件名冲突 | 脚本用 file.stem 避免覆盖 |
如果TIFF是多页的
上面脚本只处理第一页。如果需要每页都生成缩略图:
python
from PIL import ImageSequence
for i, page in enumerate(ImageSequence.Iterator(img)):
page.thumbnail(thumb_size, Image.LANCZOS)
page = page.convert('RGB') if page.mode not in ('RGB', 'L') else page
page.save(f"{output_dir}/{file.stem}_page{i}.jpg", "JPEG", quality=jpg_quality)
二、其他方法
一、GUI 工具(零代码,最快上手)
| 工具 | 平台 | 特点 |
|---|---|---|
| XnConvert | Win/Mac/Linux | 免费,拖拽批量,支持多页TIFF,可设输出尺寸 |
| IrfanView | Windows | 轻量,Batch Conversion 功能,免费 |
| FastStone | Windows | 选文件→批量转换→设尺寸→输出,三步搞定 |
| Adobe Bridge | 全平台 | 选中多个TIFF → 工具 → Photoshop → 图像处理器 |
推荐 XnConvert,免费、支持多页TIFF、可自定义缩略图尺寸,比写代码快得多。
二、系统自带命令(不装任何东西)
macOS
bash
# 批量转JPG + 缩放到256px
mkdir -p output
for f in *.tif *.tiff; do
sips -Z 256 --out output/"${f%.*}.jpg" "$f"
done
Windows PowerShell(不装软件)
powershell
mkdir output -Force
Get-ChildItem *.tif*,*.tiff | ForEach-Object {
$img = [System.Drawing.Image]::FromFile($_.FullName)
$thumb = New-Object System.Drawing.Bitmap 256, 256
$graphics = [System.Drawing.Graphics]::FromImage($thumb)
$graphics.DrawImage($img, 0, 0, 256, 256)
$thumb.Save("output\$($_.BaseName).jpg", [System.Drawing.Imaging.ImageFormat]::Jpeg)
$img.Dispose(); $thumb.Dispose(); $graphics.Dispose()
}
缺点:Windows自带的对CMYK TIFF支持差,颜色可能偏。
三、命令行工具(比Python快,比ImageMagick轻)
libvips(速度最快,内存占用最低)
bash
# 安装
brew install vips # Mac
apt install libvips-tools # Ubuntu
# 批量处理
vips thumbnail "*.tif[page=0]" 256 --format jpg --quality 85 -o output/"%s.jpg"
处理1000张图比Pillow快5-10倍,尤其适合大文件。
GraphicsMagick(ImageMagick的轻量分支)
bash
gm mogrify -path ./output -resize 256x256 -format jpg -quality 85 *.tif
四、在线批量转换(不想装任何东西)
| 网站 | 限制 |
|---|---|
| CloudConvert | 免费25次/天,支持多页TIFF |
| Convertio | 每次最多100MB,免费用户有限制 |
| IloveIMG | 简单批量,无尺寸控制 |
适合文件量少、不涉及隐私的场景。
选哪个?
| 你的情况 | 推荐 |
|---|---|
| 不想写代码,偶尔用 | XnConvert |
| Mac用户,不想装东西 | sips 命令 |
| 文件量大(上千张) | libvips |
| 已经装了ImageMagick | 直接用 magick mogrify |
| 不想装任何软件,Windows | PowerShell 脚本(颜色可能不准) |