【问题标题】:I thought PNG had better file compression than gif in terms of size. Then why is my PNG larger than my gif? I used pycharm to convert file我认为 PNG 在大小方面比 gif 具有更好的文件压缩率。那为什么我的 PNG 比我的 gif 大?我用pycharm转换文件
【发布时间】:2021-11-20 15:47:36
【问题描述】:

我用来将 BMP 转换为 GIF 的代码

click here to view the image formats

我用来将 BMP 转换为 GIF 的代码

from PIL import Image
import glob
# Create the frames
frames = []
imgs = glob.glob("*.bmp")
for i in imgs:
    new_frame = Image.open(i)
    frames.append(new_frame)

# Save into a GIF file that loops forever
frames[0].save('bmp_to_gif.gif', format='GIF',
               append_images=frames[1:],
               save_all=True,
               duration=300, loop=0)

BMP 转 PNG

from PIL import Image
Image.open("sample_1920×1280.bmp").save("sample1.png")

【问题讨论】:

  • 你从哪里得到 png 应该小于 gif 的概念?这完全取决于源材料。
  • 这并不是一个真正的平等比较,生成一个(对我们来说)未知大小的图像与单个图像的动画 GIF。
  • 两种情况下得到的颜色深度是否相同?
  • @sj95126 看一下附上的图片,我已经展示了我的 gif 文件及其文件大小。而 gif 只有 1 帧。
  • WIll it work if 是您在这里从未问过的问题。做吧,让我们知道结果

标签: python image compression png gif


【解决方案1】:

GIF 正在将图像码垛到 256 色。您的 PNG 压缩不是,保留所有原始颜色,我猜是 RGB。

您可以在使用img.convert("P", palette=Image.ADAPTIVE) 打开 BMP 后将其转换为调色板。保存为 PNG 时,请使用 optimize=True

【讨论】:

    猜你喜欢
    • 2017-10-13
    • 1970-01-01
    • 2018-06-15
    • 2016-01-06
    • 2010-11-01
    • 2015-01-19
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    相关资源
    最近更新 更多