How to preserve color palette when resizing

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
jmaeding
Posts: 54
Joined: 2006-05-03T09:48:26-07:00

How to preserve color palette when resizing

Post by jmaeding »

I typically keep images of maps and things as tifs with 8-bit color, with an optimized palette.
I do this through corel photo paint.
Many times, I want to resize a map or photo by 50%. I am using convert.exe so I tried:
convert USGS.tif -resize 50%% -compress rle USGSsmaller.tif

The %% is because I am running from a windows batch file, it works fine with other operations.
The result of the resize is the colorspace gets set to 48 bit, and the image is huge. So I tried:
convert USGS.tif -resize 50%% -colors 256 -compress rle USGSsmall.tif

with very bad results, mostly blue pixels, ugly.
Is there something I need to do to resize, while keeping the palette intact, or some other way to end up with 8bit optimized palette?
I don't mind if it makes the 48bit , then converts to 8 bit, I just dont know how to do it. -colors 256 is not doing it.
thanks
James Maeding
Civil Engineer / Programmer
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Post by el_supremo »

You seem to have the Q16 version of ImageMagick installed, so it is saving each pixel as 16 bits. Add -depth 8 before the output filename.

Pete
jmaeding
Posts: 54
Joined: 2006-05-03T09:48:26-07:00

Post by jmaeding »

I tried that just now, did not work. The size action worked fine but I got a 24 bit rgb image instead of 8 bit.

Any reason why I should be using the Q16 as opposed to Q8? I just chose the one that looked the most powerful. Maybe its not suited to people that only work with 24bit and lower colors.
thanks
James Maeding
Civil Engineer / Programmer
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Use -scale or -filter point to stop the resize creating new colors.
Results are however not as good.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jmaeding
Posts: 54
Joined: 2006-05-03T09:48:26-07:00

Post by jmaeding »

I tried that and many other combinations, I get 24 bit every time.
I even uninstalled Q16 and put on Q8 version, same results.

One clue is if I just run a:
convert USGS.tif -depth 8 USGS8.tif

It errors out. It says a bunch of lines like "unexpected field...".
The sizing works fine, its the palette stuff that is failing.
I can post a portion of the image if there is a convenient place so you can see.
I am amazed I am hitting these issues with the first image I try.
Many other things work super well with IM, you would think the resample would be cake :)
James Maeding
Civil Engineer / Programmer
Post Reply