Imagemagick lower PNG depth - ios

I have a huge number of images provided from various artists working on a project. The images have varying specs, but all are PNGs. Some are 8-bit indexed (palette), others are true color with alpha 32-bit and 64-bit PNGs.
Now, I am trying to use imagemagick to push all these images to a single coherent format, but I am facing a painful issue. I noticed that images that have been converted from truecolor with alpha (16-bit channel depth) work like a charm. However, 8-bit per channel images, or possibly lower/higher images get somewhat corrupted and the rendering engine (on iOS) we have will not display the images properly.
Is there a way to simply convert all images robustly to a single 8-bit per channel truecolor with alpha PNG format (RGBA8888)?
(NOTE: I read in the wikipedia link true color & alpha is at least 32 bits per channel, I need to reduce the depth by trimming it to reduce the file size. The rendering engine will also take care of that.)
I tried the following commands:
/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 {}
Here are two images from running the last command, the second one doesn't run on the engine:
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
And...
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
This is how it was before it got corrupted:
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

If you are using ImageMagick, you can force the images to be written as RGBA8888 PNG with
/opt/local/bin/convert input.png png32:output.png

Related

How to perform Bilinear Interpolation to a masked image?

Suppose I have an image with mask, valid pixels are masked as 1 and others 0, how to perform bilinear interpolation to fill all the invalid pixels?
for example, image:
1, 0, 0, 4
mask:
1, 0, 0, 1
interpolation result should be:
1, 2, 3, 4
The valid pixels are not regularly arranged, a more complicated sample, image:
4, 0, 6, 0,
0, 8, 5, 0
5, 3, 0, 0
mask:
1, 0, 1, 0,
0, 1, 1, 0
1, 1, 0, 0
interpolate with scipy.interpolate.interp2d and the result has many holes and noise

Why does resizing in graphicsmagick yield larger file size

Preamble: I have a list of several thousand jp2 images that I need to quickly check for content. (I have more computer processing time than physical time.) There are several conversion steps that I am planning to take to reduce the file size from 200+k to less than 50k. One of these steps was to resize the image. The original images are all 4k+x2k+ in size. However, when I used graphicmagick's convert command the file size doubled although the new file has smaller dimensions. Less is more! The command I used was convert -resize 1000x1000 myOldFile.jp2 myNewFile.jp2
My question: Why did the file size double and what can I do to decrease the image dimensions while at the same time reducing the file size?
Results:
The result of identify -verbose for both files is as follows.
Old File
Image: myOldFile.jp2
Format: JP2 (JPEG-2000 File Format Syntax)
Mime type: image/jp2
Class: DirectClass
Geometry: 4368x2912+0+0
Units: Undefined
Colorspace: sRGB
Type: TrueColor
Base type: Undefined
Endianess: Undefined
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
Pixels: 12719616
Red:
min: 0 (0)
max: 242 (0.94902)
mean: 161.286 (0.632496)
standard deviation: 83.2707 (0.326552)
kurtosis: -0.933893
skewness: -0.997317
entropy: 0.706322
Green:
min: 0 (0)
max: 232 (0.909804)
mean: 151.98 (0.596001)
standard deviation: 76.5239 (0.300094)
kurtosis: -0.952932
skewness: -0.979073
entropy: 0.729028
Blue:
min: 0 (0)
max: 207 (0.811765)
mean: 122.977 (0.482262)
standard deviation: 63.5478 (0.249207)
kurtosis: -0.9993
skewness: -0.936829
entropy: 0.775844
Image statistics:
Overall:
min: 0 (0)
max: 242 (0.94902)
mean: 145.414 (0.570253)
standard deviation: 74.4475 (0.291951)
kurtosis: -1.06722
skewness: -0.805503
entropy: 0.737065
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: white
Border color: srgb(223,223,223)
Matte color: grey74
Transparent color: black
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 4368x2912+0+0
Dispose: Undefined
Iterations: 0
Compression: JPEG2000
Orientation: Undefined
Properties:
date:create: 2019-08-01T15:14:22-07:00
date:modify: 2009-06-03T13:13:55-07:00
signature: ffd44383040859b7138d337c52e2545e2b49601f949a2bbbdfc7b8592d60360b
Artifacts:
filename: myOldFile.jp2
verbose: true
Tainted: False
Filesize: 268346B
Number pixels: 12.7196M
Pixels per second: 7.43837MB
User time: 1.550u
Elapsed time: 0:02.710
Version: ImageMagick 6.9.9-40 Q16 x86_64 2019-05-16 http://www.imagemagick.org
New File
Image: myNewFile.jp2
Format: JP2 (JPEG-2000 File Format Syntax)
Mime type: image/jp2
Class: DirectClass
Geometry: 1000x667+0+0
Units: Undefined
Colorspace: sRGB
Type: TrueColor
Base type: Undefined
Endianess: Undefined
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
Pixels: 667000
Red:
min: 0 (0)
max: 254 (0.996078)
mean: 160.789 (0.630545)
standard deviation: 83.1402 (0.32604)
kurtosis: -0.923213
skewness: -1.00025
entropy: 0.710373
Green:
min: 2 (0.00784314)
max: 245 (0.960784)
mean: 151.482 (0.594048)
standard deviation: 76.3802 (0.29953)
kurtosis: -0.941261
skewness: -0.981966
entropy: 0.732809
Blue:
min: 0 (0)
max: 221 (0.866667)
mean: 122.48 (0.480313)
standard deviation: 63.3749 (0.248529)
kurtosis: -0.985942
skewness: -0.939624
entropy: 0.777783
Image statistics:
Overall:
min: 0 (0)
max: 254 (0.996078)
mean: 144.917 (0.568302)
standard deviation: 74.2984 (0.291366)
kurtosis: -1.05759
skewness: -0.80746
entropy: 0.740322
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: white
Border color: srgb(223,223,223)
Matte color: grey74
Transparent color: black
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 1000x667+0+0
Dispose: Undefined
Iterations: 0
Compression: JPEG2000
Orientation: Undefined
Properties:
date:create: 2019-08-01T15:40:21-07:00
date:modify: 2019-08-01T15:40:21-07:00
signature: 061752e248846335b5f064c85e83ff71542f7ddd55f5327cf146b8aacd685285
Artifacts:
filename: myNewFile.jp2
verbose: true
Tainted: False
Filesize: 511396B
Number pixels: 667000
Pixels per second: 4.16875MB
User time: 0.160u
Elapsed time: 0:01.160
Version: ImageMagick 6.9.9-40 Q16 x86_64 2019-05-16 http://www.imagemagick.org

Extract part of an image to identify

I try to get verbose information about a part of an image. I read the doc of imageMagick and as far as I understand it, it should be possible to call identify with the -extract option. But, when I call it, I got an error message:
'unrecognized option: -extract'.
This is my commandline call identify -verbose -extract 20x20+0+20 ./mosaicTemplate.jpg
Does anyone knows, what is wrong with my commandline Call or has an convenient workaround?
Thanks in advance!
Simon
Create a test image like this:
convert -size 500x500 gradient:red-blue image.png
Now check details of top left corner where image is pretty red:
convert image.png -crop 20x20+0+0 -verbose info:
Image: image.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 20x20+0+0
Units: Undefined
Type: Palette
Endianess: Undefined
Colorspace: sRGB
Depth: 16-bit
Channel depth:
red: 16-bit
green: 1-bit
blue: 16-bit
Channel statistics:
Pixels: 400
Red:
min: 63040 (0.961929)
max: 65535 (1)
mean: 64287.3 (0.980962) <--- very red
standard deviation: 757.295 (0.0115556)
kurtosis: -1.20609
skewness: 0.000125086
entropy: 1
Green:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
entropy: nan
Blue:
min: 0 (0)
max: 2495 (0.0380713)
mean: 1247.65 (0.0190379) <--- not very blue
standard deviation: 757.295 (0.0115556)
kurtosis: -1.20609
skewness: -0.000125086
entropy: 1
Now check details of bottom left corner where it is more blue:
convert image.png -crop 20x20+0+480 -verbose info:
Image: image.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 20x20+0+0
Units: Undefined
Type: Palette
Endianess: Undefined
Colorspace: sRGB
Depth: 16-bit
Channel depth:
red: 16-bit
green: 1-bit
blue: 16-bit
Channel statistics:
Pixels: 400
Red:
min: 0 (0)
max: 2495 (0.0380713)
mean: 1247.65 (0.0190379) <--- not very red
standard deviation: 757.295 (0.0115556)
kurtosis: -1.20609
skewness: -0.000125086
entropy: 1
Green:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
entropy: nan
Blue:
min: 63040 (0.961929)
max: 65535 (1)
mean: 64287.3 (0.980962) <--- very blue
standard deviation: 757.295 (0.0115556)
kurtosis: -1.20609
skewness: 0.000125086
entropy: 1

Is there any way to pass ImageMagick an RGBA array to render it as an image?

Question pretty much says it all.
The idea is to generate procedural PNG's. I'm aware of imageMagick's '-fx' operator but it's very slow.
A workaround could be to save my array to .bmp (which is pretty much just saving it) and then just use ImageMagick to convert .bmp to .png but it would be nice to have a more direct approach.
You may be able to exploit ImageMagick's TXT image format for this purpose. I can't tell you anything about the performance, you'll have to test it.
Start by trying the following:
convert some-small.png some-small-png.txt
convert some-small.jpg some-small-jpg.txt
convert some-small.tif some-small-tif.txt
[...]
(This conversion can be slow too.)
Then do the reverse conversions:
convert some-small-png.txt some-small-roundtripped.png
convert some-small-png.txt some-small-roundtripped.jpg
convert some-small-png.txt some-small-roundtripped.tif
[...]
(This conversion should be faster.)
Compare initial PNG, JPEG, TIFF with the roundtripped ones.
Look at the *.txt files to understand their format:
It is a formal textual description enumerating, line by line, for each pixel's coordinates and the respective color values.
The first line is a header describing the image's dimensions, its depth and the colorspace used.
Also be aware that on each line everything after the # (which depicts the hex values of the respective colors) is not required -- you may regard it as a comment. Also, all remaining blanks on each line are optional.
It means you could re-organize your RGBA array in such a way that it matches ImageMagick's TXT image format (as I said, you don't require neither the hex values nor the friendly color names) and then simply call convert (after adding the required header line).
Update
I'll give you an example.
Here is the extremly simple, stripped of blanks, names and #hex values for colors, 2x2 pixels sRGBA mini-image represented by 2x2.txt. It's file size is 129 Bytes.
cat 2x2.txt
# ImageMagick pixel enumeration: 2,2,65535,srgba
0,0:(65535,0,0,65535)
0,1:(0,65535,0,65535)
1,0:(0,0,65535,65535)
1,1:(0,0,0,0)
You an convert this into a PNG image:
convert 2x2.txt 2x2.png
2x2.png is 293 Bytes. Since a 2x2 pixel PNG is a bit too small to be recognized on a website, we can convert to something bigger:
convert 2x2.txt -scale 10000% 200x200.png
convert 2x2.txt -scale 1000% 20x20.png
These 2 PNGs are recognizable on a web page:
To demonstrate the full format (not stripped of blanks, names or #hex values for colors), let's create the respective 20x20.txt and look at it:
convert 20x20.png 20x20.txt
cat 20x20.txt
# ImageMagick pixel enumeration: 20,20,255,srgba
0,0: (255, 0, 0,255) #FF0000 red
1,0: (255, 0, 0,255) #FF0000 red
2,0: (255, 0, 0,255) #FF0000 red
3,0: (255, 0, 0,255) #FF0000 red
4,0: (255, 0, 0,255) #FF0000 red
5,0: (255, 0, 0,255) #FF0000 red
6,0: (255, 0, 0,255) #FF0000 red
7,0: (255, 0, 0,255) #FF0000 red
8,0: (255, 0, 0,255) #FF0000 red
9,0: (255, 0, 0,255) #FF0000 red
10,0: ( 0, 0,255,255) #0000FF blue
11,0: ( 0, 0,255,255) #0000FF blue
[....]
[....]
[....]
7,19: ( 0,255, 0,255) #00FF00 lime
8,19: ( 0,255, 0,255) #00FF00 lime
9,19: ( 0,255, 0,255) #00FF00 lime
10,19: ( 0, 0, 0, 0) #00000000 none
11,19: ( 0, 0, 0, 0) #00000000 none
12,19: ( 0, 0, 0, 0) #00000000 none
13,19: ( 0, 0, 0, 0) #00000000 none
14,19: ( 0, 0, 0, 0) #00000000 none
15,19: ( 0, 0, 0, 0) #00000000 none
16,19: ( 0, 0, 0, 0) #00000000 none
17,19: ( 0, 0, 0, 0) #00000000 none
18,19: ( 0, 0, 0, 0) #00000000 none
19,19: ( 0, 0, 0, 0) #00000000 none

Imagemagick convert tools generates bigger file size for smaller geometry?

I tried to use convert of imagemagick 6.5.6 to make a smaller version from original JPEG file in both file size and geometry. The command I used is:
convert tj/p1.jpg -resize 500x tj/456c2e75fe0faa57fd1cfd87117e0963/p1.jpg
The result is funny, the original is 1102x1542+0+0 in 164kb, the converted one is 500x700+0+0 in 174kb. The pixel count is almost the 20% of the original version, with much bigger file size. So I add -strip options to remove all the verbose information in JPEG profile.
convert tj/p1.jpg -strip -resize 500x tj/500_p1.jpg
The 500_p1.jpg is 500x700+0+0 in 173kb, only 1kb less.
Also I tried to use -thumbnail for it.
convert tj/p1.jpg -thumbnail 500x tj/th/p1.jpg
The thumbed jpeg is 500x700+0+0 in 173kb as well.
Finally I found the -quality can help to reduce images. But 75% quality takes 107kb, 25% quality takes only 50kb with visible loss of detail. But the original quality factor is unknown.
Does anyone have similar issues? Hereafter are the image profiles generated by identify. I found the major differences as following:
Geometry: 1102x1542->500x700
print size: 11x15->5x7
Units: Undefined->PixelsPerInch
Quality: unknown->92
Nr. of Pixels: 1.621mb->342kb
Detail of profiles:
Original:
Image: tj/p1.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Class: DirectClass
Geometry: 1102x1542+0+0
Resolution: 100x100
Print size: 11.02x15.42
Units: Undefined
Type: TrueColor
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
red:
min: 0 (0)
max: 255 (1)
mean: 218.106 (0.855319)
standard deviation: 52.7336 (0.206798)
kurtosis: 5.04278
skewness: -2.24455
green:
min: 0 (0)
max: 255 (1)
mean: 158.476 (0.621473)
standard deviation: 92.9844 (0.364645)
kurtosis: -1.24112
skewness: -0.535292
blue:
min: 0 (0)
max: 255 (1)
mean: 113.282 (0.444244)
standard deviation: 99.7003 (0.390981)
kurtosis: -1.59582
skewness: 0.278377
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 122.466 (0.480259)
standard deviation: 108.274 (0.424604)
kurtosis: -1.78198
skewness: 0.0115088
Rendering intent: Undefined
Interlace: None
Background color: white
Border color: rgb(223,223,223)
Matte color: grey74
Transparent color: black
Page geometry: 1102x1542+0+0
Dispose: Undefined
Iterations: 0
Compression: JPEG
Orientation: Undefined
Properties:
date:create: 2010-10-22T08:35:35+08:00
date:modify: 2010-09-30T10:52:06+08:00
jpeg:colorspace: 2
jpeg:sampling-factor: 2x2,1x1,1x1
signature: cdbd3f63986f0a7c4cd20aedcf9123d91df97e0cb7388f59059b4676fd36d481
Profiles:
Profile-APP12: 15 bytes
Artifacts:
verbose: true
Tainted: False
Filesize: 164kb
Number pixels: 1.621mb
Pixels per second: 20.51mb
User time: 0.078u
Elapsed time: 0:01
Version: ImageMagick 6.5.6-5 2009-09-25 Q16 OpenMP http://www.imagemagick.org
Converted:
Image: tj/456c2e75fe0faa57fd1cfd87117e0963/p1.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Class: DirectClass
Geometry: 500x700+0+0
Resolution: 100x100
Print size: 5x7
Units: PixelsPerInch
Type: TrueColor
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
red:
min: 0 (0)
max: 255 (1)
mean: 216.75 (0.849999)
standard deviation: 50.1075 (0.1965)
kurtosis: 4.066
skewness: -2.03195
green:
min: 0 (0)
max: 255 (1)
mean: 158.316 (0.620846)
standard deviation: 89.1433 (0.349582)
kurtosis: -1.17694
skewness: -0.52022
blue:
min: 0 (0)
max: 255 (1)
mean: 113.58 (0.445411)
standard deviation: 96.3298 (0.377764)
kurtosis: -1.53577
skewness: 0.287937
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 122.161 (0.479064)
standard deviation: 106.052 (0.415889)
kurtosis: -1.7498
skewness: 0.00808184
Rendering intent: Undefined
Interlace: None
Background color: white
Border color: rgb(223,223,223)
Matte color: grey74
Transparent color: black
Page geometry: 500x700+0+0
Dispose: Undefined
Iterations: 0
Compression: JPEG
Quality: 92
Orientation: Undefined
Properties:
date:create: 2010-10-22T10:27:18+08:00
date:modify: 2010-10-22T10:31:08+08:00
jpeg:colorspace: 2
jpeg:sampling-factor: 2x2,1x1,1x1
signature: 63202ddf9106d3374fe3a396f5105ce8099051cf807ceb2ab5a19532957cec10
Artifacts:
verbose: true
Tainted: False
Filesize: 174kb
Number pixels: 342kb
Version: ImageMagick 6.5.6-5 2009-09-25 Q16 OpenMP http://www.imagemagick.org

Resources