1

我有大量来自从事一个项目的艺术家提供的图像。这些图像有不同的规格,但都是PNG。有些是 8 位索引(调色板),有些是带有 alpha 32 位和 64 位 PNG 的真彩色。

现在,我正在尝试使用 imagemagick 将所有这些图像推送到单一的连贯格式,但我面临着一个痛苦的问题。我注意到从带有 alpha(16 位通道深度)的真彩色转换而来的图像非常有用。但是,每通道 8 位图像,或者可能更低/更高的图像会有些损坏,并且我们拥有的渲染引擎(在 iOS 上)将无法正确显示图像。

有没有办法简单地将所有图像可靠地转换为具有 alpha PNG 格式(RGBA8888)的每通道 8 位真彩色?

(注意:我在 wikipedia 链接中读到真彩色和 alpha 每个通道至少 32 位,我需要通过修剪来减少深度以减小文件大小。渲染引擎也会处理这个问题。)

我尝试了以下命令:

/opt/local/bin/convert -depth 8 {} {}
/opt/local/bin/convert {} -depth 8 {}
/opt/local/bin/convert {} -colorspace sRGB -depth 8 {}
/opt/local/bin/convert {} -type truecolormatte -depth 8 {}

这是运行最后一个命令的两个图像,第二个不在引擎上运行:

Image: bu_hu_townhall_l01.png
  Format: PNG (Portable Network Graphics)
  Class: DirectClass
  Geometry: 640x558+0+0
  Resolution: 28.35x28.35
  Print size: 22.575x19.6825
  Units: PixelsPerCentimeter
  Type: TrueColorAlpha
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
    alpha: 8-bit
  Channel statistics:
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 207.468 (0.8136)
      standard deviation: 60.7017 (0.238046)
      kurtosis: 1.18939
      skewness: -1.39109
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 205.419 (0.805565)
      standard deviation: 56.0321 (0.219734)
      kurtosis: 1.15995
      skewness: -1.22368
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 174.337 (0.683673)
      standard deviation: 79.2051 (0.310608)
      kurtosis: -0.8628
      skewness: -0.578582
    Alpha:
      min: 0 (0)
      max: 255 (1)
      mean: 96.4893 (0.37839)
      standard deviation: 123.454 (0.484134)
      kurtosis: -1.74557
      skewness: -0.501528
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 186.434 (0.731112)
      standard deviation: 84.1704 (0.33008)
      kurtosis: 0.210139
      skewness: -1.19818
  Alpha: srgba(255,255,255,0)   #FFFFFF00
  Rendering intent: Perceptual
  Gamma: 0.45455
  Chromaticity:
    red primary: (0.63999,0.33001)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.05999)
    white point: (0.31269,0.32899)
  Background color: white
  Border color: srgba(223,223,223,1)
  Matte color: grey74
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 640x558+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
  Properties:
    date:create: 2013-07-19T12:48:10-07:00
    date:modify: 2013-07-19T12:48:10-07:00
    png:bKGD: chunk was found (see Background color, above)
    png:cHRM: chunk was found (see Chromaticity, above)
    png:gAMA: gamma=0.45454544 (See Gamma, above)
    png:IHDR.bit-depth-orig: 8
    png:IHDR.bit_depth: 8
    png:IHDR.color-type-orig: 6
    png:IHDR.color_type: 6 (RGBA)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 640, 558
    png:pHYs: x_res=2835, y_res=2835, units=1
    png:sRGB: intent=0 (Perceptual Intent)
    png:text: 2 tEXt/zTXt/iTXt chunks were found
    signature: 547acae3cbfddef87d1ec49fb4dbe259772343ed121a8f9bfe2f1846fc542cf0
  Artifacts:
    filename: bu_hu_townhall_l01.png
    verbose: true
  Tainted: False
  Filesize: 333KB
  Number pixels: 357K
  Pixels per second: 17.86MB
  User time: 0.010u
  Elapsed time: 0:01.019
  Version: ImageMagick 6.8.6-0 2013-07-03 Q16 http://www.imagemagick.org

和...

Image: red_circle.png
  Format: PNG (Portable Network Graphics)
  Class: DirectClass
  Geometry: 256x256+0+0
  Resolution: 28.35x28.35
  Print size: 9.02998x9.02998
  Units: PixelsPerCentimeter
  Type: PaletteAlpha
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 1-bit
    green: 1-bit
    blue: 1-bit
    alpha: 8-bit
  Channel statistics:
    Red:
      min: 255 (1)
      max: 255 (1)
      mean: 255 (1)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Green:
      min: 0 (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Blue:
      min: 0 (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Alpha:
      min: 0 (0)
      max: 40 (0.156863)
      mean: 6.30113 (0.0247103)
      standard deviation: 10.7071 (0.0419887)
      kurtosis: 1.47694
      skewness: -1.66221
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 125.925 (0.493822)
      standard deviation: 5.35356 (0.0209944)
      kurtosis: 309547
      skewness: 77.6945
  Alpha: srgba(255,0,0,0)   #FF000000
  Colors: 41
  Histogram:
     37164: (255,  0,  0,  0) #FF000000 srgba(255,0,0,0)
      4416: (255,  0,  0,  1) #FF000001 srgba(255,0,0,0.00392157)
      1974: (255,  0,  0,  2) #FF000002 srgba(255,0,0,0.00784314)
      1394: (255,  0,  0,  4) #FF000004 srgba(255,0,0,0.0156863)
      1154: (255,  0,  0,  5) #FF000005 srgba(255,0,0,0.0196078)
       982: (255,  0,  0,  8) #FF000008 srgba(255,0,0,0.0313725)
       942: (255,  0,  0,  7) #FF000007 srgba(255,0,0,0.027451)
       893: (255,  0,  0, 10) #FF00000A srgba(255,0,0,0.0392157)
       758: (255,  0,  0,  3) #FF000003 srgba(255,0,0,0.0117647)
       754: (255,  0,  0, 11) #FF00000B srgba(255,0,0,0.0431373)
       752: (255,  0,  0, 14) #FF00000E srgba(255,0,0,0.054902)
       749: (255,  0,  0, 13) #FF00000D srgba(255,0,0,0.0509804)
       698: (255,  0,  0, 16) #FF000010 srgba(255,0,0,0.0627451)
       684: (255,  0,  0, 17) #FF000011 srgba(255,0,0,0.0666667)
       657: (255,  0,  0, 19) #FF000013 srgba(255,0,0,0.0745098)
       636: (255,  0,  0, 20) #FF000014 srgba(255,0,0,0.0784314)
       635: (255,  0,  0, 38) #FF000026 srgba(255,0,0,0.14902)
       630: (255,  0,  0, 32) #FF000020 srgba(255,0,0,0.12549)
       604: (255,  0,  0, 23) #FF000017 srgba(255,0,0,0.0901961)
       598: (255,  0,  0, 26) #FF00001A srgba(255,0,0,0.101961)
       589: (255,  0,  0, 28) #FF00001C srgba(255,0,0,0.109804)
       574: (255,  0,  0, 34) #FF000022 srgba(255,0,0,0.133333)
       574: (255,  0,  0, 31) #FF00001F srgba(255,0,0,0.121569)
       568: (255,  0,  0, 22) #FF000016 srgba(255,0,0,0.0862745)
       551: (255,  0,  0, 29) #FF00001D srgba(255,0,0,0.113725)
       542: (255,  0,  0,  6) #FF000006 srgba(255,0,0,0.0235294)
       541: (255,  0,  0, 25) #FF000019 srgba(255,0,0,0.0980392)
       516: (255,  0,  0, 37) #FF000025 srgba(255,0,0,0.145098)
       485: (255,  0,  0, 35) #FF000023 srgba(255,0,0,0.137255)
       387: (255,  0,  0,  9) #FF000009 srgba(255,0,0,0.0352941)
       381: (255,  0,  0, 12) #FF00000C srgba(255,0,0,0.0470588)
       327: (255,  0,  0, 36) #FF000024 srgba(255,0,0,0.141176)
       327: (255,  0,  0, 24) #FF000018 srgba(255,0,0,0.0941176)
       326: (255,  0,  0, 15) #FF00000F srgba(255,0,0,0.0588235)
       316: (255,  0,  0, 21) #FF000015 srgba(255,0,0,0.0823529)
       305: (255,  0,  0, 18) #FF000012 srgba(255,0,0,0.0705882)
       304: (255,  0,  0, 27) #FF00001B srgba(255,0,0,0.105882)
       270: (255,  0,  0, 33) #FF000021 srgba(255,0,0,0.129412)
       254: (255,  0,  0, 30) #FF00001E srgba(255,0,0,0.117647)
       251: (255,  0,  0, 39) #FF000027 srgba(255,0,0,0.152941)
        74: (255,  0,  0, 40) #FF000028 srgba(255,0,0,0.156863)
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64733,0.33636)
    green primary: (0.28904,0.6052)
    blue primary: (0.1235,0.0424)
    white point: (0.28021,0.296)
  Background color: white
  Border color: srgba(223,223,223,1)
  Matte color: grey74
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 256x256+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
  Properties:
    date:create: 2013-07-19T12:48:29-07:00
    date:modify: 2013-07-19T12:48:29-07:00
    png:bKGD: chunk was found (see Background color, above)
    png:cHRM: chunk was found (see Chromaticity, above)
    png:iCCP: chunk was found
    png:IHDR.bit-depth-orig: 8
    png:IHDR.bit_depth: 8
    png:IHDR.color-type-orig: 3
    png:IHDR.color_type: 3 (Indexed)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 256, 256
    png:pHYs: x_res=2835, y_res=2835, units=1
    png:PLTE.number_colors: 42
    png:text: 2 tEXt/zTXt/iTXt chunks were found
    png:tRNS: chunk was found
    signature: f41a73e5fe161c06aa147572380ab95b6e43a411fa533b6533af37e2d19a161e
  Profiles:
    Profile-icc: 3224 bytes
      Description: Display
      Manufacturer: Display
      Model: Display
      Copyright: Copyright Apple, Inc., 2013
  Artifacts:
    filename: red_circle.png
    verbose: true
  Tainted: False
  Filesize: 8.44KB
  Number pixels: 65.5K
  Pixels per second: 0B
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 6.8.6-0 2013-07-03 Q16 http://www.imagemagick.org

这是它被破坏之前的样子:

Image: red_circle.png
  Format: PNG (Portable Network Graphics)
  Class: DirectClass
  Geometry: 256x256+0+0
  Resolution: 28.35x28.35
  Print size: 9.02998x9.02998
  Units: PixelsPerCentimeter
  Type: PaletteAlpha
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 1-bit
    green: 1-bit
    blue: 1-bit
    alpha: 8-bit
  Channel statistics:
    Red:
      min: 255 (1)
      max: 255 (1)
      mean: 255 (1)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Green:
      min: 0 (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Blue:
      min: 0 (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Alpha:
      min: 0 (0)
      max: 40 (0.156863)
      mean: 6.30113 (0.0247103)
      standard deviation: 10.7071 (0.0419887)
      kurtosis: 1.47694
      skewness: -1.66221
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 125.925 (0.493822)
      standard deviation: 5.35356 (0.0209944)
      kurtosis: 309547
      skewness: 77.6945
  Alpha: srgba(255,0,0,0)   #FF000000
  Colors: 41
  Histogram:
     37164: (255,  0,  0,  0) #FF000000 srgba(255,0,0,0)
      4416: (255,  0,  0,  1) #FF000001 srgba(255,0,0,0.00392157)
      1974: (255,  0,  0,  2) #FF000002 srgba(255,0,0,0.00784314)
      1394: (255,  0,  0,  4) #FF000004 srgba(255,0,0,0.0156863)
      1154: (255,  0,  0,  5) #FF000005 srgba(255,0,0,0.0196078)
       982: (255,  0,  0,  8) #FF000008 srgba(255,0,0,0.0313725)
       942: (255,  0,  0,  7) #FF000007 srgba(255,0,0,0.027451)
       893: (255,  0,  0, 10) #FF00000A srgba(255,0,0,0.0392157)
       758: (255,  0,  0,  3) #FF000003 srgba(255,0,0,0.0117647)
       754: (255,  0,  0, 11) #FF00000B srgba(255,0,0,0.0431373)
       752: (255,  0,  0, 14) #FF00000E srgba(255,0,0,0.054902)
       749: (255,  0,  0, 13) #FF00000D srgba(255,0,0,0.0509804)
       698: (255,  0,  0, 16) #FF000010 srgba(255,0,0,0.0627451)
       684: (255,  0,  0, 17) #FF000011 srgba(255,0,0,0.0666667)
       657: (255,  0,  0, 19) #FF000013 srgba(255,0,0,0.0745098)
       636: (255,  0,  0, 20) #FF000014 srgba(255,0,0,0.0784314)
       635: (255,  0,  0, 38) #FF000026 srgba(255,0,0,0.14902)
       630: (255,  0,  0, 32) #FF000020 srgba(255,0,0,0.12549)
       604: (255,  0,  0, 23) #FF000017 srgba(255,0,0,0.0901961)
       598: (255,  0,  0, 26) #FF00001A srgba(255,0,0,0.101961)
       589: (255,  0,  0, 28) #FF00001C srgba(255,0,0,0.109804)
       574: (255,  0,  0, 34) #FF000022 srgba(255,0,0,0.133333)
       574: (255,  0,  0, 31) #FF00001F srgba(255,0,0,0.121569)
       568: (255,  0,  0, 22) #FF000016 srgba(255,0,0,0.0862745)
       551: (255,  0,  0, 29) #FF00001D srgba(255,0,0,0.113725)
       542: (255,  0,  0,  6) #FF000006 srgba(255,0,0,0.0235294)
       541: (255,  0,  0, 25) #FF000019 srgba(255,0,0,0.0980392)
       516: (255,  0,  0, 37) #FF000025 srgba(255,0,0,0.145098)
       485: (255,  0,  0, 35) #FF000023 srgba(255,0,0,0.137255)
       387: (255,  0,  0,  9) #FF000009 srgba(255,0,0,0.0352941)
       381: (255,  0,  0, 12) #FF00000C srgba(255,0,0,0.0470588)
       327: (255,  0,  0, 36) #FF000024 srgba(255,0,0,0.141176)
       327: (255,  0,  0, 24) #FF000018 srgba(255,0,0,0.0941176)
       326: (255,  0,  0, 15) #FF00000F srgba(255,0,0,0.0588235)
       316: (255,  0,  0, 21) #FF000015 srgba(255,0,0,0.0823529)
       305: (255,  0,  0, 18) #FF000012 srgba(255,0,0,0.0705882)
       304: (255,  0,  0, 27) #FF00001B srgba(255,0,0,0.105882)
       270: (255,  0,  0, 33) #FF000021 srgba(255,0,0,0.129412)
       254: (255,  0,  0, 30) #FF00001E srgba(255,0,0,0.117647)
       251: (255,  0,  0, 39) #FF000027 srgba(255,0,0,0.152941)
        74: (255,  0,  0, 40) #FF000028 srgba(255,0,0,0.156863)
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64733,0.33636)
    green primary: (0.28904,0.6052)
    blue primary: (0.1235,0.0424)
    white point: (0.28021,0.296)
  Background color: white
  Border color: srgba(223,223,223,1)
  Matte color: grey74
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 256x256+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
  Properties:
    date:create: 2013-07-18T20:55:49-07:00
    date:modify: 2013-07-18T20:55:49-07:00
    png:cHRM: chunk was found (see Chromaticity, above)
    png:iCCP: chunk was found
    png:IHDR.bit-depth-orig: 8
    png:IHDR.bit_depth: 8
    png:IHDR.color-type-orig: 6
    png:IHDR.color_type: 6 (RGBA)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 256, 256
    png:pHYs: x_res=2835, y_res=2835, units=1
    signature: f41a73e5fe161c06aa147572380ab95b6e43a411fa533b6533af37e2d19a161e
  Profiles:
    Profile-icc: 3224 bytes
      Description: Display
      Manufacturer: Display
      Model: Display
      Copyright: Copyright Apple, Inc., 2013
  Artifacts:
    filename: red_circle.png
    verbose: true
  Tainted: False
  Filesize: 11.2KB
  Number pixels: 65.5K
  Pixels per second: 0B
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 6.8.6-0 2013-07-03 Q16 http://www.imagemagick.org
4

1 回答 1

3

如果您使用的是 ImageMagick,则可以强制将图像写入为 RGBA8888 PNG

 /opt/local/bin/convert input.png png32:output.png
于 2014-03-28T15:46:05.790 回答