Page 1 of 1

Convert image to 256 colors palette

Posted: 2016-04-15T03:22:15-07:00
by olee92
Hi. In order to display images from the web on a pebble smartwatch I want to reduce their colors on my server before displaying them.
In order to do that I'm using -remap with the 64 colors palette that is provided from the pebble documentation:

Code: Select all

convert in.ong -dither FloydSteinberg -remap palette.gif png8:out.png
For testing I used this image / palette:
Image Image
The processed one looks like this
Image

But when I try displaying this image on the pebble, it ends up like this (ignore borders):
Image

If I instead use GIMP to reduce the colors, the image looks the same, but works correctly on the pebble.

I tried using the identify command on both images and this was the result:
Working image: http://pastebin.com/raw/wGYb0NT1
Broken image: http://pastebin.com/raw/YUHjZnDn

The only difference I could find was the color palette, which was padded to 256 colors with black in the working image.
I also noticed that I get the same broken image with gimp, if I tell it to remove unused colors from the image palette.

Is there any way to achieve the same result with imagemagick as I did with gimp?

I'm using ImageMagick version 6.8.9-9

Re: Convert image to 256 colors palette

Posted: 2016-04-15T03:56:28-07:00
by snibgo
It sounds as if Pebble is broken: it can use only 64 colours but needs a map with 256 entries. Is that right?

If you provided palette.gif, people could experiment to find an IM solution.

You could try "-define png:preserve-colormap=true".

Re: Convert image to 256 colors palette

Posted: 2016-04-15T05:05:29-07:00
by olee92
On this page you can find the color palette in different formats: https://developer.pebble.com/guides/app ... es/images/

In the meantime I will try the "-define png:preserve-colormap=true" option you proposed.

Thanks for the quick feedback!

Re: Convert image to 256 colors palette

Posted: 2016-04-15T05:18:52-07:00
by olee92
When I try adding that option, I get this error:

Code: Select all

convert in.png -resize 144x168\> -dither FloydSteinberg -remap color_palette.gif -define png:preserve-colormap=true -define png:compression-level=9 -define png:compression-strategy=0 -define png:exclude-chunk=all png8:out.png
convert: Valid palette required for paletted images `in.png' @ error/png.c/MagickPNGErrorHandler/1645.

Re: Convert image to 256 colors palette

Posted: 2016-04-15T05:41:59-07:00
by snibgo
Why do you have "png8:" for the output?

I can't find palette.gif on the page you linked. I did find pebble_colors_64.gif, which has a colormap with only 64 entries. This suggests that pebble doesn't need to have 256 entries.

Re: Convert image to 256 colors palette

Posted: 2016-04-15T07:04:57-07:00
by olee92
Yes, pebble_colors_64.gif is the palette (I just renamed it).
But the interesting thing is that the broken image is the one where the palette in the image has only 64 entries and the 256 entry GIMP converted version works correctly.
Also the file size is different - 64 color palette broken IM picture is 8.25 kB - the working 256 color palette (with lots of black colors in it) is 7.40 kB in size. This looks quite contractional...