python3 图片 4通道转成3通道 1通道转成3通道 图片压缩实例

Noella ·
更新时间:2024-09-20
· 577 次阅读

我就废话不多说了,直接上代码吧!

from PIL import Image # 通道转换 def change_image_channels(image, image_path):     # 4通道转3通道 if image.mode == 'RGBA':         r, g, b, a = image.split()         image = Image.merge("RGB", (r, g, b))         image.save(image_path)     # 1 通道转3通道     elif image.mode != 'RGB':         image = image.convert("RGB")         os.remove(image_path)         image.save(image_path)     return image # 图片压缩 def image_compression(image): w, h = image.size print(w, h) image.thumbnail((int(w / 1.1), int(h / 1.1))) image.save("./car.png") return image if __name__ == "__main__":     image = Image.open("./timg.png")     new_image = process_image_channels(image, "./time.png")     print(new_image.mode)

以上这篇python3 图片 4通道转成3通道 1通道转成3通道 图片压缩实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持软件开发网。

您可能感兴趣的文章:python 实现单通道转3通道



图片 图片压缩 Python3 Python 压缩

需要 登录 后方可回复, 如果你还没有账号请 注册新账号