Convert image to 256 colors palette

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
olee92
Posts: 4
Joined: 2016-04-15T02:42:09-07:00
Authentication code: 1151

Convert image to 256 colors palette

Post 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
Last edited by olee92 on 2016-04-15T07:06:02-07:00, edited 2 times in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert image to 256 colors palette

Post 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".
snibgo's IM pages: im.snibgo.com
olee92
Posts: 4
Joined: 2016-04-15T02:42:09-07:00
Authentication code: 1151

Re: Convert image to 256 colors palette

Post 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!
olee92
Posts: 4
Joined: 2016-04-15T02:42:09-07:00
Authentication code: 1151

Re: Convert image to 256 colors palette

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert image to 256 colors palette

Post 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.
snibgo's IM pages: im.snibgo.com
olee92
Posts: 4
Joined: 2016-04-15T02:42:09-07:00
Authentication code: 1151

Re: Convert image to 256 colors palette

Post 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...
Post Reply