批处理图片尺寸修改成4的倍数

Unity中使用ETC2压缩格式要求图片尺寸必须是4的倍数,所以写个脚本修改一下尺寸

Python要先安装Pillow
pip install Pillow

import os
from PIL import Image

in_dir = r"F:\UnityProjects\Porject"
out_dir = r"E:\VineyardValleyImages"

file_list = None
with open("file_list1.txt", "r", encoding="utf8") as list_file:
    file_list = list_file.readlines()

for file in file_list:
    file = file.strip()
    if not file.endswith(".png"):
        continue
    try:
        image = Image.open(os.path.join(in_dir, file))
        size_w = image.size[0] - (image.size[0] % 4)
        size_h = image.size[1] - (image.size[1] % 4)
        if size_w < 50 or size_h < 50:
            continue
        image_size = image.resize((size_w, size_h), Image.ANTIALIAS)
        out_path = os.path.join(out_dir, file)
        out_path_dir = os.path.dirname(out_path)
        if not os.path.exists(out_path_dir):
            os.makedirs(out_path_dir)
        image_size.save(out_path)
    except Exception as exc:
        pass
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

achonor

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值