Page 1 of 1
How can I convert a png to 2 bits per pixel?
Posted: 2014-10-31T15:31:49-07:00
by Lassar
I have been trying to optimize a png for the web.
Had some luck with this.
"convert xxx.png depth 1 colors 1 yyy.png"
It actually converted it to a 1 bit per pixel png.
I tried "convert xxx.png depth 2 colors 2 yyy.png" and did not have any luck with it.
Is this a limitation of the ImageMagik?
I know png's can have a bit depth of 2 bits per pixel.
I tired irfanview, and did not have any luck.
Are there other tools on the net, that can convert png's to 2 bits per pixel?
Re: How can I convert a png to 2 bits per pixel?
Posted: 2014-10-31T16:27:33-07:00
by snibgo
"-colors 4" will reduce the image to 4 colours, and make a palette image with 4 entries, so each pixel needs just 2 pixels.
Re: How can I convert a png to 2 bits per pixel?
Posted: 2019-02-11T03:11:04-07:00
by barbos
unfortunately it didn't works in some cases.
For example, here is png I want to make 2 bit indexed color:
https://i.imgur.com/AmjOlkT.png
Here is original PNG content:
Code: Select all
IHDR = 0x49484452
width = 512
height = 512
bitDepth = 8
colorType = 3
compression = 0
filter = 0
interlace = 0
PLTE = 0x504c5445: 768 bytes
IDAT = 0x49444154: 30641 bytes
IEND = 0x49454e44
I executed the following command:
Code: Select all
convert 555.png -colors 2 555_2.png
And got this result:
https://i.imgur.com/DYfJw80.png
At a glance looks good, but let's look under the hood:
Code: Select all
IHDR = 0x49484452
width = 512
height = 512
bitDepth = 8
colorType = 0
compression = 0
filter = 0
interlace = 0
gAMA = 0x67414d41: gamma = 45455 [0.45455]
cHRM = 0x6348524d: 32 bytes
bKGD = 0x624b4744: 2 bytes
tIME = 0x74494d45: 7 bytes
IDAT = 0x49444154: 6824 bytes
tEXt = 0x74455874: keyword="date:create", text="2019-02-11T11:59:11+02:00"
tEXt = 0x74455874: keyword="date:modify", text="2019-02-11T11:39:37+02:00"
IEND = 0x49454e44
as you can see, the new image is still 8 bit color! And now it even with no palette!
I tried to modify original picture, reduce colors to 16 before processing but imagemagick convert anyway removes palette and make it 8 bit color!
Why it happens? Is this a bug?
Is there any other way to make 2 bit indexed color output?
PS: I used the latest version from this site:
https://imagemagick.org/download/binari ... 16-x86.zip
Re: How can I convert a png to 2 bits per pixel?
Posted: 2019-02-11T07:04:32-07:00
by snibgo
"-type palette" will tell IM to make a paletted file. There is no method to tell IM to use a certain number of entries in the palette.