I want to convert a 24bit images png. bmp etc to 8bit png and always detect the background color and set it as color #1 of the palette in a color map, so that it automatically become sthe binary transparency of an image. In the past irfanview did that but now it always gives me a wrong color:
is there a command that can preserve to good quality a Png, and always detect the background color, if not detect the pixel at the upper left corner, i can always set it to the color i want. Command line is fine, gui is even better. I decided to try this when irfanview doesn't do it right. For the png quality some programs like gimp do not make that good quality png, I like irfanview's quality when you decrease color depth and i wonder of this imagemagick can do the same quality and palette as i like.
Convert png to png8 and detect background color
Convert png to png8 and detect background color
Last edited by imagemcr on 2016-07-04T00:17:13-07:00, edited 2 times in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert png to png8 and detect background color
As far as I know, there is no way to tell IM what colours to place in particular slots in the palette map.... and set it as color #1 of the palette in a color map, ...
snibgo's IM pages: im.snibgo.com
Re: Convert png to png8 and detect background color
Programs like iview and others when you save a PNG or GIF it detects the background color and sets it as the color to use for transparency, usually puts it as first color. I thought transparent-color can do something but if it can't then fine, i will look for another program.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert png to png8 and detect background color
I believe you can set the PNG8 transparency by using -transparent yourbackgroundcolor. But I am not an expert on PNG. The PNG developer will be able to recommend the proper method.
I do not know how to detect the background color of an image automatically (other than getting the histogram and finding the most frequent color, see http://www.imagemagick.org/Usage/files/#histogram. You can have IM choose any pixel you want or just specify it yourself.
Try
That works using the IM internal image logo:
To get the color in the top left corner (unix syntax for IM 6)
I do not know how to detect the background color of an image automatically (other than getting the histogram and finding the most frequent color, see http://www.imagemagick.org/Usage/files/#histogram. You can have IM choose any pixel you want or just specify it yourself.
Try
Code: Select all
convert yourimage.png +dither -colors 256 -transparent somecolor PNG8:result.png
Code: Select all
convert logo: +dither -colors 256 -transparent white PNG8:logo8.png
Code: Select all
color=`convert logo: +dither -colors 256 -format "%[pixel:u.p{0,0}]" info:`
convert logo: +dither -colors 256 -transparent "$color" PNG8:logo8.png
Re: Convert png to png8 and detect background color
Thanks fmw42, I will see which of these i can use until they fix other programs to do this.