使用 imagemagick 将 GIF 图像转换为 PNG,但得到的是 RGBA 图像而不是 paletissed 版本

Convert GIF image to PNG with imagemagick, but getting a RGBA image instead of a paletissed version

此题与相似。不同之处在于,当您想要 PNG 作为输出时,那里提出的解决方案似乎不起作用。

简而言之,我有一个 GIF 图像,我将其转换为 PNG 以进行进一步处理(使用 Python rasterio)。我想获得一个具有预期四个通道的常规 PNG 图像。

我试过这个:

convert -type TrueColorAlpha Image.gif Image.png

然而,我得到了一个非常优化的版本,似乎是苍白的,只有一个频道。这是我使用 gdalinfo:

获得的元数据
Driver: GIF/Graphics Interchange Format (.gif)
Files: ESZA_20210204_105147_0_source.gif
Size is 480, 530
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  530.0)
Upper Right (  480.0,    0.0)
Lower Right (  480.0,  530.0)
Center      (  240.0,  265.0)
Band 1 Block=480x1 Type=Byte, ColorInterp=Palette
  Metadata:
    GIF_BACKGROUND=0
  Color Table (RGB with 64 entries)
    0: 0,0,0,255
    1: 89,111,115,255
    2: 127,127,127,255
    3: 188,50,31,255
    4: 255,0,0,255
    5: 255,127,0,255
    6: 200,0,90,255
    7: 208,112,99,255
    8: 67,131,35,255
    9: 0,192,0,255
   10: 0,255,0,255
   11: 255,187,0,255
   12: 248,210,21,255
   13: 255,255,0,255
   14: 155,155,117,255
   15: 250,222,83,255
   16: 3,49,147,255
   17: 37,85,163,255
   18: 69,110,178,255
   19: 0,0,252,255
   20: 98,133,190,255
   21: 0,148,252,255
   22: 123,152,201,255
   23: 0,252,252,255
   24: 222,156,145,255
   25: 250,234,152,255
   26: 233,194,186,255
   27: 149,172,211,255
   28: 172,191,221,255
   29: 243,222,218,255
   30: 253,245,203,255
   31: 192,205,228,255
   32: 208,218,235,255
   33: 222,229,242,255
   34: 250,239,237,255
   35: 255,251,232,255
   36: 231,236,245,255
   37: 239,243,248,255
   38: 243,246,250,255
   39: 247,249,252,255
   40: 253,250,249,255
   41: 250,251,253,255
   42: 254,254,252,255
   43: 252,253,254,255
   44: 255,255,255,255
   45: 0,0,0,255
   46: 0,0,0,255
   47: 0,0,0,255
   48: 0,0,0,255
   49: 0,0,0,255
   50: 0,0,0,255
   51: 0,0,0,255
   52: 0,0,0,255
   53: 0,0,0,255
   54: 0,0,0,255
   55: 0,0,0,255
   56: 0,0,0,255
   57: 0,0,0,255
   58: 0,0,0,255
   59: 0,0,0,255
   60: 0,0,0,255
   61: 0,0,0,255
   62: 0,0,0,255
   63: 0,0,0,255

知道如何强制 imagemagick 生成常规的四通道 PNG 图像吗?

要将 GIF 转换为 PNG,如果要设置颜色深度,请使用 PNG 前缀。这是 PNG 特有的。

对于 32 位颜色 (RGBA):

convert image.gif PNG32:image.png

对于 24 位颜色 (RGB):

convert image.gif PNG24:image.png

对于 8 位调色板颜色:

convert image.gif PNG8:image.png

https://legacy.imagemagick.org/Usage/formats/#png_formats and https://legacy.imagemagick.org/Usage/formats/#png_write