Converting a 24 bit png to 4 bit png not successfull

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
prasadmenon
Posts: 3
Joined: 2013-12-03T06:16:58-07:00
Authentication code: 6789

Converting a 24 bit png to 4 bit png not successfull

Post by prasadmenon »

Hi All,

I am new to imagemagik. I have a query while using it. The scenario is as follows.

I have a 24 bit png.

http://wikisend.com/download/816040/image_5778.png

I want to convert it to 4 bit png. I tried the following command

convert image_5778.png PNG8:correctimage.png This is successfully converting 24 bit to 8 bit png, but when I tried

convert image_5778.png -depth 4 correctimage.png It is not getting converted to 4 bit png.

Please let me know how I can save it correctly to 4 bit for my use and what is wrong in the command I used.

Note: I am using ImageMagick-6.8.7-Q16 in Windows machine.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting a 24 bit png to 4 bit png not successfull

Post by snibgo »

I think you are confusing 24 bits per pixel and 8 bits per channel per pixel.

Your input image has pixeldepth 24 (bits per pixel). But there are only 2 colours: black and white.

After this command ...

Code: Select all

convert image_5778.png i.png
... the result has 2 palette entries, with pixeldepth of 1.

IM generally tries to make the file as small as possible. You can force it to be 24-bits (per pixel) with PNG24:out.png but I don't think you can force 4-bits/channel/pixel.
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Converting a 24 bit png to 4 bit png not successfull

Post by glennrp »

Yes, the converted image has a palette with two entries, black and white. This should be representable without loss
as a 4-bit image. I don't know why convert is rejecting the attempt to write the 1-bit image in a 4-bit format. I'll
take a look at that.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Converting a 24 bit png to 4 bit png not successfull

Post by glennrp »

It turns out to be a side effect of the recent split of linear and sRGB colorspaces. A fix is in the SVN repository, r=13919 and will appear in IM-6.8.7-9 in a few days.
prasadmenon
Posts: 3
Joined: 2013-12-03T06:16:58-07:00
Authentication code: 6789

Re: Converting a 24 bit png to 4 bit png not successfull

Post by prasadmenon »

Thanks for the inputs. So if I understand correctly, I will be able to test this only when IM-6.8.7-9 gets released. Please let me know once it gets released.

I am waiting for it.
prasadmenon
Posts: 3
Joined: 2013-12-03T06:16:58-07:00
Authentication code: 6789

Re: Converting a 24 bit png to 4 bit png not successfull

Post by prasadmenon »

Glen,

Can you please try converting the attached image to 4 bit using the development version of Imagemagick and share it here. It is for a urgent project requirement. Any help will be appreciated.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Converting a 24 bit png to 4 bit png not successfull

Post by glennrp »

prasadmenon wrote:Glen,
Can you please try converting the attached image to 4 bit using the development version of Imagemagick and share it here. It is for a urgent project requirement. Any help will be appreciated.
Using this command:

Code: Select all

convert image_5778.png -define png:color-type=0 -define png:bit-depth=4 -define png:exclude-chunks=all image_depth4.png
The last -define isn't necessary but it doesn't make a lot of sense to include gAMA and cHRM chunks in a black-and-white image so I used that option to exclude them.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Converting a 24 bit png to 4 bit png not successfull

Post by glennrp »

This bug was fixed in IM-6.8.7-9 but has reappeared in IM-6.9.1-3.
Post Reply