【问题标题】:Imagemagick GIF Dimensions Repeat Over and OverImagemagick GIF 尺寸一遍又一遍地重复
【发布时间】:2016-05-15 23:07:51
【问题描述】:

我在 Python 脚本中使用 Imagemagick 识别来确定图像的尺寸。在分析动画 GIF 时,尺寸会一次又一次地重复,例如500 375500 375500 375500 375500 375500 375500 375500 375.

为什么会这样?如何将此输出清理为简单的宽度/高度?

产生此结果的 Python 脚本:

#!/usr/bin/env python
import subprocess, logging

# identify -ping -format "%w %h" test.gif
dimensions = subprocess.check_output([
    r'C:\Program Files\ImageMagick-6.9.3-Q16\identify.exe',
    '-ping',
    '-format',
    '%w %h',
    "../www/content/test.gif"
])

# b string to utf-8 string
dimensions = dimensions.decode("utf-8")

logging.warning(dimensions)

而日志中的输出如下:

WARNING:root:500 375500 375500 375500 375500 375500 375500 375500 375

【问题讨论】:

    标签: python imagemagick subprocess imagemagick-convert


    【解决方案1】:

    编辑

    对此答案的评论是正确的-最好的方法是使用image.gif[0]

    原答案

    尺寸会一次又一次地重复,因为动画 gif 有多个帧。当我注意到每个 gif 的尺寸重复不同的次数时,我就明白了。

    我将 '%w %h' 更改为 '%w %h;'并使用 split 来隔离第一帧。

    dimensions = dimensions.decode("utf-8").split(';') #375 500
    

    【讨论】:

    • 您可以只使用image.gif[0] 来识别/隔离第一帧的尺寸。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-16
    • 2021-05-30
    • 1970-01-01
    • 2021-07-05
    • 2017-11-19
    相关资源
    最近更新 更多