RGB2PCT(1)

πŸ“¦
version 3.4.3 Β· 2 versions
, in epel 9

πŸ’– NAME πŸ’–

rgb2pct β€” and yes bestie, this is straight out of the GDAL manual, section 1, we're fancy β€” it converts a 24bit RGB image to 8bit paletted. That's the whole job. She takes your chunky true-colour pic and gives you a slim little palette queen back. πŸŽ€


✨ SYNOPSIS ✨

rgb2pct.py [-n colors | -pct palette_file] [-of format] <source_file> <dest_file>

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so here's the tea β˜• β€” this utility computes an optimal pseudo-color table for whatever RGB image you hand it, and it does that with a median cut algorithm running over a downsampled RGB histogram. Very demure, very efficient, no cap.

Then it flips your image into a pseudo-colored image using that color table. And the conversion? It uses Floyd-Steinberg dithering (error diffusion) to maximize output image visual quality. Like, she's literally diffusing the errors so your gradients don't look crusty. Iconic behavior honestly. 🌈

πŸ’… the options, one by one πŸ’…

  • -n <color> β€” picks how many colors go in the generated color table. Defaults to 256. Must be between 2 and 256 β€” no, you cannot have 1 color, and no, you cannot have 300. Boundaries exist for a reason bestie. πŸ’€
  • -pct <palette_file> β€” yoinks the color table out of <palette_file> instead of computing a fresh one. Super useful when you want a consistent color table across multiple files (matching vibes across the whole feed, yk?). The <palette_file> has to be either a raster file in a GDAL supported format with a palette, or a color file in a supported format (txt, qml, qlr). No random PNGs, she has standards. 🧚
  • -of <format> β€” sets the output format. Starting with GDAL 2.3, if you don't specify it, the format is guessed from the extension (previously was GTiff). Use the short format name. And only output formats supporting pseudo-color tables should be used β€” don't set her up to fail. 🫢
  • <source_file> β€” the input RGB file. Your raw material. ✨
  • <dest_file> β€” the output pseudo-colored file that will be created. Your glow-up result. πŸ‘‘
NOTE: rgb2pct.py is a Python script, and will only work if GDAL was built with Python support. Fr fr, if your GDAL skipped Python, this whole thing is a no-op and you'll be sad. Check first. 😭

πŸ“ EXAMPLE πŸ“

So if you wanna hand-create the palette β€” and honestly the simplest text format for that is likely the GDAL VRT format β€” here's the move. In the following example a VRT was created in a text editor with a small 4 color palette, with the RGBA colors 238/238/238/255, 237/237/237/255, 236/236/236/255 and 229/229/229/255.

rgb2pct.py -pct palette.vrt rgb.tif pseudo-colored.tif
more < palette.vrt
<VRTDataset rasterXSize="226" rasterYSize="271">
    <VRTRasterBand dataType="Byte" band="1">
        <ColorInterp>Palette</ColorInterp>
        <ColorTable>
        <Entry c1="238" c2="238" c3="238" c4="255"/>
        <Entry c1="237" c2="237" c3="237" c4="255"/>
        <Entry c1="236" c2="236" c3="236" c4="255"/>
        <Entry c1="229" c2="229" c3="229" c4="255"/>
        </ColorTable>
    </VRTRasterBand>
</VRTDataset>

Four whole colors. Minimalist. Lowkey obsessed. πŸ¦‹


πŸ‘‘ AUTHOR πŸ‘‘

Frank Warmerdam <warmerdam@pobox.com> β€” the legend himself, respect on his name. 🫑


1998-2026


And that's the page, bestie πŸ’œ β€” this lil artifact is dated Jan 08, 2026 and lives at the bottom of the RGB2PCT(1) manual like a little signature. Go make some palettes. Mwah. πŸ’‹βœ¨

πŸ“¦ where this page comes from