将 .jpg 图像转换为 .png [英] Converting .jpg images to .png

查看:70
本文介绍了将 .jpg 图像转换为 .png的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我环顾四周并阅读了文档,但没有找到任何方法或解决方案,所以我在这里提问.是否有任何可用的包可以使用 Python 将 JPG 图像转换为 PNG 图像?

I've looked around and read the docs, and found no way or solution, so I ask here. Is there any packages available to use Python to convert a JPG image to a PNG image?

推荐答案

你总是可以使用 Python Image图书馆 (PIL) 用于此目的.可能还有其他包/库,但我以前用过它来转换格式.

You could always use the Python Image Library (PIL) for this purpose. There might be other packages/libraries too, but I've used this before to convert between formats.

这适用于 Windows 下的 Python 2.7 (Python Imaging Library 1.1.7 for Python 2.7),我在 2.7.1 和 2.7.2 中使用它

This works with Python 2.7 under Windows (Python Imaging Library 1.1.7 for Python 2.7), I'm using it with 2.7.1 and 2.7.2

from PIL import Image

im = Image.open('Foto.jpg')
im.save('Foto.png')

请注意,您最初的问题没有提到 Python 的版本或您使用的操作系统.当然,这可能会有所不同:)

Note your original question didn't mention the version of Python or the OS you are using. That may make a difference of course :)

这篇关于将 .jpg 图像转换为 .png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆