Image:
http://s3-us-west-2.amazonaws.com/qiniu-bs/bigger.png //clolormodel = palette 256
Command :
convert bigger.png -thumbnail 500x -colors 256 -type Palette a.png //fail
convert bigger.png -thumbnail 450x -colors 256 -type Palette a.png //success
debug info:
fail:
2015-03-16T18:09:00+08:00 0:00.120 0.170u 6.8.8 Coder convert[27782]: png.c/WriteOnePNGImage/8574/Coder
74 image->colors=256
75 2015-03-16T18:09:00+08:00 0:00.120 0.170u 6.8.8 Coder convert[27782]: png.c/WriteOnePNGImage/8582/Coder
76 Regenerate the colormap
77 2015-03-16T18:09:00+08:00 0:00.170 0.220u 6.8.8 Coder convert[27782]: png.c/WriteOnePNGImage/8699/Coder
78 Check colormap for background (65535,65535,65535)
79 2015-03-16T18:09:00+08:00 0:00.170 0.220u 6.8.8 Coder convert[27782]: png.c/WriteOnePNGImage/8719/Coder
80 background_color index is 256
81 2015-03-16T18:09:00+08:00 0:00.170 0.220u 6.8.8 Coder convert[27782]: png.c/WriteOnePNGImage/8734/Coder
82 image has more than 256 colors
83 2015-03-16T18:09:00+08:00 0:00.170 0.220u 6.8.8 Coder convert[27782]: png.c/WriteOnePNGImage/8935/Coder
84 image->colors=256
85 2015-03-16T18:09:00+08:00 0:00.170 0.220u 6.8.8 Coder convert[27782]: png.c/WriteOnePNGImage/8959/Coder
86 number_transparent = 0
87 2015-03-16T18:09:00+08:00 0:00.170 0.220u 6.8.8 Coder convert[27782]: png.c/WriteOnePNGImage/8973/Coder
88 number_opaque > 256
success:
9 2015-03-16T18:11:39+08:00 0:00.100 0.130u 6.8.8 Coder convert[27857]: png.c/WriteOnePNGImage/8719/Coder
80 background_color index is 253 //这开始取得值和索引值就与上面不同
81 2015-03-16T18:11:39+08:00 0:00.100 0.130u 6.8.8 Coder convert[27857]: png.c/WriteOnePNGImage/8738/Coder
82 image has 254 colors
83 2015-03-16T18:11:39+08:00 0:00.100 0.130u 6.8.8 Coder convert[27857]: png.c/WriteOnePNGImage/8815/Coder
84 Sort the new colormap
85 2015-03-16T18:11:39+08:00 0:00.100 0.130u 6.8.8 Coder convert[27857]: png.c/WriteOnePNGImage/8870/Coder
86 AcquireImageColormap
87 2015-03-16T18:11:39+08:00 0:00.100 0.140u 6.8.8 Coder convert[27857]: png.c/WriteOnePNGImage/8886/Coder
88 image->colors=254 (254)
89 2015-03-16T18:11:39+08:00 0:00.100 0.140u 6.8.8 Coder convert[27857]: png.c/WriteOnePNGImage/8890/Coder
90 Update the pixel indexes
91 2015-03-16T18:11:39+08:00 0:00.110 0.150u 6.8.8 Coder convert[27857]: png.c/WriteOnePNGImage/8935/Coder
92 image->colors=254
93 2015-03-16T18:11:39+08:00 0:00.110 0.150u 6.8.8 Coder convert[27857]: png.c/WriteOnePNGImage/8940/Coder
94 i (red,green,blue,opacity)
Now,can you tell me why this situation,and how to resolve it.
In my opinion ,colors's value should equal the colormodel's value when convert the image.
Colors Error
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Colors Error
I think the problem is that the total number of opaque colours plus the number of (semi-)transparent pixels must be <= 256. "-alpha off" will ensure there are no (semi-)transparent pixels.
Code: Select all
convert bigger.png -thumbnail 500x -alpha off -colors 256 -type palette a.png
snibgo's IM pages: im.snibgo.com
Re: Colors Error
1、snibgo wrote:I think the problem is that the total number of opaque colours plus the number of (semi-)transparent pixels must be <= 256. "-alpha off" will ensure there are no (semi-)transparent pixels.Code: Select all
convert bigger.png -thumbnail 500x -alpha off -colors 256 -type palette a.png
why this is success
convert bigger.png -thumbnail 450x -colors 256 -type Palette a.png //notice :the same image,only thumbnail different
2、
And convert png ,although we don't add alpha off,the result hasn't alpha.
So we need add alpha on not off.
Image: http://s3-us-west-2.amazonaws.com/qiniu-bs/2.png
convert 2.png -thumbnail 500x -colors 2 -type palette a.png //although we don't add alpha off ,but result hasnt't alpha
So ,i think we need add alpha on not off
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Colors Error
Have you tried it? For me, IM v6.9.0-0, "-alpha on" does not work. "-alpha off" does work.needkane wrote:So ,i think we need add alpha on not off
It works because after reducing colors it has only 255 colours.needkane wrote:1、why this is success
convert bigger.png -thumbnail 450x -colors 256 -type Palette a.png //notice :the same image,only thumbnail different
Code: Select all
f:\web\im>%IM%convert bigger.png -thumbnail 450x -colors 256 -unique-colors info:
bigger.png PNG 255x1 8-bit sRGB 255c 0.000u 0:00.000
Thumbnail 500 makes 256 colors:
Code: Select all
f:\web\im>%IM%convert bigger.png -thumbnail 500x -colors 256 -unique-colors info :
bigger.png PNG 256x1 8-bit sRGB 256c 0.000u 0:00.000
snibgo's IM pages: im.snibgo.com
Re: Colors Error
so,how to resolve thissnibgo wrote:Have you tried it? For me, IM v6.9.0-0, "-alpha on" does not work. "-alpha off" does work.needkane wrote:So ,i think we need add alpha on not off
It works because after reducing colors it has only 255 colours.needkane wrote:1、why this is success
convert bigger.png -thumbnail 450x -colors 256 -type Palette a.png //notice :the same image,only thumbnail different255 colors plus one transparent fits into a 256 palette.Code: Select all
f:\web\im>%IM%convert bigger.png -thumbnail 450x -colors 256 -unique-colors info: bigger.png PNG 255x1 8-bit sRGB 255c 0.000u 0:00.000
Thumbnail 500 makes 256 colors:The problem seems to be that IM doesn't realise there is no need for a transparent entry in the palette. So "-alpha off" works.Code: Select all
f:\web\im>%IM%convert bigger.png -thumbnail 500x -colors 256 -unique-colors info : bigger.png PNG 256x1 8-bit sRGB 256c 0.000u 0:00.000
Image: http://s3-us-west-2.amazonaws.com/qiniu-bs/2.png
convert 2.png -thumbnail 500x -colors 2 -type palette a.png //although we don't add alpha off ,but result hasnt't alpha
result is opaque,we need add alpha on.Can you tell me a common method to resolve bigger.png and 2.png
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Colors Error
I don't know what you are trying to do, or what the "common method" should do. If the input has transparency, do you want the output to have transparency? Is binary transparency good enough?
I don't use "-thumbnail". I use "-resize" or "scale". If you don't want new colours then "-scale" may be useful.
I don't use palette files, and don't know much about them.
I don't use "-thumbnail". I use "-resize" or "scale". If you don't want new colours then "-scale" may be useful.
I don't use palette files, and don't know much about them.
snibgo's IM pages: im.snibgo.com
Re: Colors Error
Eliminate the bKGD chunk, or make the bacground color equal to one of
the colors already in your palette. As it is, the bKGD chunk takes up
an additional entry in the palette.
File: 2.png (294 bytes)
chunk IHDR at offset 0x0000c, length 13
420 x 420 image, 1-bit palette, non-interlaced
chunk PLTE at offset 0x00025, length 6: 2 palette entries
chunk tRNS at offset 0x00037, length 2: 2 transparency entries
chunk IDAT at offset 0x00045, length 205
zlib: deflated, 32K window, default compression
chunk IEND at offset 0x0011e, length 0
No errors detected in 2.png (5 chunks, 98.7% compression).
pngcheck -v a.png
File: a.png (1629 bytes)
chunk IHDR at offset 0x0000c, length 13
500 x 500 image, 2-bit palette, non-interlaced
chunk gAMA at offset 0x00025, length 4: 0.45455
chunk cHRM at offset 0x00035, length 32
White x = 0.3127 y = 0.329, Red x = 0.64 y = 0.33
Green x = 0.3 y = 0.6, Blue x = 0.15 y = 0.06
chunk PLTE at offset 0x00061, length 9: 3 palette entries
chunk bKGD at offset 0x00076, length 1
index = 2
chunk tIME at offset 0x00083, length 7: 17 Mar 2015 11:51:09 UTC
chunk IDAT at offset 0x00096, length 1028
zlib: deflated, 32K window, maximum compression
chunk tEXt at offset 0x004a6, length 37, keyword: date:create
chunk tEXt at offset 0x004d7, length 37, keyword: date:modify
chunk tEXt at offset 0x00508, length 78, keyword: software
chunk tEXt at offset 0x00562, length 24, keyword: Thumb::Document::Pages
chunk tEXt at offset 0x00586, length 24, keyword: Thumb::Image::Height
chunk tEXt at offset 0x005aa, length 23, keyword: Thumb::Image::Width
chunk tEXt at offset 0x005cd, length 25, keyword: Thumb::Mimetype
chunk tEXt at offset 0x005f2, length 23, keyword: Thumb::MTime
chunk tEXt at offset 0x00615, length 17, keyword: Thumb::Size
chunk tEXt at offset 0x00632, length 23, keyword: Thumb::URI
chunk IEND at offset 0x00655, length 0
No errors detected in a.png (18 chunks, 97.4% compression).
glenn.rp>
glenn.rp> q16convert 2.png -thumbnail 500x -colors 2 -define png:exclude-chunk=bkgd -type palette a.png
glenn.rp> pngcheck a.png
OK: a.png (500x500, 1-bit palette, non-interlaced, 95.4%).
glenn.rp> pngcheck -v a.png
File: a.png (1460 bytes)
chunk IHDR at offset 0x0000c, length 13
500 x 500 image, 1-bit palette, non-interlaced
chunk gAMA at offset 0x00025, length 4: 0.45455
chunk cHRM at offset 0x00035, length 32
White x = 0.3127 y = 0.329, Red x = 0.64 y = 0.33
Green x = 0.3 y = 0.6, Blue x = 0.15 y = 0.06
chunk PLTE at offset 0x00061, length 6: 2 palette entries
chunk tIME at offset 0x00073, length 7: 17 Mar 2015 11:51:09 UTC
chunk IDAT at offset 0x00086, length 875
zlib: deflated, 32K window, maximum compression
chunk tEXt at offset 0x003fd, length 37, keyword: date:create
chunk tEXt at offset 0x0042e, length 37, keyword: date:modify
chunk tEXt at offset 0x0045f, length 78, keyword: software
chunk tEXt at offset 0x004b9, length 24, keyword: Thumb::Document::Pages
chunk tEXt at offset 0x004dd, length 24, keyword: Thumb::Image::Height
chunk tEXt at offset 0x00501, length 23, keyword: Thumb::Image::Width
chunk tEXt at offset 0x00524, length 25, keyword: Thumb::Mimetype
chunk tEXt at offset 0x00549, length 23, keyword: Thumb::MTime
chunk tEXt at offset 0x0056c, length 17, keyword: Thumb::Size
chunk tEXt at offset 0x00589, length 23, keyword: Thumb::URI
chunk IEND at offset 0x005ac, length 0
No errors detected in a.png (17 chunks, 95.4% compression).
the colors already in your palette. As it is, the bKGD chunk takes up
an additional entry in the palette.
File: 2.png (294 bytes)
chunk IHDR at offset 0x0000c, length 13
420 x 420 image, 1-bit palette, non-interlaced
chunk PLTE at offset 0x00025, length 6: 2 palette entries
chunk tRNS at offset 0x00037, length 2: 2 transparency entries
chunk IDAT at offset 0x00045, length 205
zlib: deflated, 32K window, default compression
chunk IEND at offset 0x0011e, length 0
No errors detected in 2.png (5 chunks, 98.7% compression).
pngcheck -v a.png
File: a.png (1629 bytes)
chunk IHDR at offset 0x0000c, length 13
500 x 500 image, 2-bit palette, non-interlaced
chunk gAMA at offset 0x00025, length 4: 0.45455
chunk cHRM at offset 0x00035, length 32
White x = 0.3127 y = 0.329, Red x = 0.64 y = 0.33
Green x = 0.3 y = 0.6, Blue x = 0.15 y = 0.06
chunk PLTE at offset 0x00061, length 9: 3 palette entries
chunk bKGD at offset 0x00076, length 1
index = 2
chunk tIME at offset 0x00083, length 7: 17 Mar 2015 11:51:09 UTC
chunk IDAT at offset 0x00096, length 1028
zlib: deflated, 32K window, maximum compression
chunk tEXt at offset 0x004a6, length 37, keyword: date:create
chunk tEXt at offset 0x004d7, length 37, keyword: date:modify
chunk tEXt at offset 0x00508, length 78, keyword: software
chunk tEXt at offset 0x00562, length 24, keyword: Thumb::Document::Pages
chunk tEXt at offset 0x00586, length 24, keyword: Thumb::Image::Height
chunk tEXt at offset 0x005aa, length 23, keyword: Thumb::Image::Width
chunk tEXt at offset 0x005cd, length 25, keyword: Thumb::Mimetype
chunk tEXt at offset 0x005f2, length 23, keyword: Thumb::MTime
chunk tEXt at offset 0x00615, length 17, keyword: Thumb::Size
chunk tEXt at offset 0x00632, length 23, keyword: Thumb::URI
chunk IEND at offset 0x00655, length 0
No errors detected in a.png (18 chunks, 97.4% compression).
glenn.rp>
glenn.rp> q16convert 2.png -thumbnail 500x -colors 2 -define png:exclude-chunk=bkgd -type palette a.png
glenn.rp> pngcheck a.png
OK: a.png (500x500, 1-bit palette, non-interlaced, 95.4%).
glenn.rp> pngcheck -v a.png
File: a.png (1460 bytes)
chunk IHDR at offset 0x0000c, length 13
500 x 500 image, 1-bit palette, non-interlaced
chunk gAMA at offset 0x00025, length 4: 0.45455
chunk cHRM at offset 0x00035, length 32
White x = 0.3127 y = 0.329, Red x = 0.64 y = 0.33
Green x = 0.3 y = 0.6, Blue x = 0.15 y = 0.06
chunk PLTE at offset 0x00061, length 6: 2 palette entries
chunk tIME at offset 0x00073, length 7: 17 Mar 2015 11:51:09 UTC
chunk IDAT at offset 0x00086, length 875
zlib: deflated, 32K window, maximum compression
chunk tEXt at offset 0x003fd, length 37, keyword: date:create
chunk tEXt at offset 0x0042e, length 37, keyword: date:modify
chunk tEXt at offset 0x0045f, length 78, keyword: software
chunk tEXt at offset 0x004b9, length 24, keyword: Thumb::Document::Pages
chunk tEXt at offset 0x004dd, length 24, keyword: Thumb::Image::Height
chunk tEXt at offset 0x00501, length 23, keyword: Thumb::Image::Width
chunk tEXt at offset 0x00524, length 25, keyword: Thumb::Mimetype
chunk tEXt at offset 0x00549, length 23, keyword: Thumb::MTime
chunk tEXt at offset 0x0056c, length 17, keyword: Thumb::Size
chunk tEXt at offset 0x00589, length 23, keyword: Thumb::URI
chunk IEND at offset 0x005ac, length 0
No errors detected in a.png (17 chunks, 95.4% compression).