Settings

Theme

Show HN: Palette Manipulator

bztsrc.gitlab.io

3 points by skrellm 6 days ago · 8 comments · 1 min read

Reader

PalTool is the ultimate swiss-army knife for converting palettes and reducing image sizes even in animations. Also smoothly converts between APNG, animated WebP and GIF.

Available as a dependecy-free CLI tool for Windows, Linux and as a web-service.

gwbas1c 6 days ago

What do you mean by "converting palettes"? Perhaps give some examples, with some before and after images.

  • skrellmOP 6 days ago

    I mean all palette related conversions. See the README in https://gitlab.com/bztsrc/paltool

    For example, you can say, take a true-color animated WebP, quantize it to 64 colors max, but make sure the first 16 colors is the same as the default VGA palette, then save the result as an animated GIF.

    There's no point in example images, because the power of this tool is, you have full control on specifying how the conversion should be done. Just quantize to 256 individual colors? Sure. Convert to web-safe palette? Got you covered. Limit the colors to 8 for each 4 x 4 pixel blocks? Smooth sailing.

    Full disclosure: it generates much better results than Imagemagick "png8:", and it handles animated PNGs too.

    • gwbas1c 6 days ago

      TLDR to your response to me.

      You should update the page to say that. I'm not going to jump through all those hoops to understand what a link on Hacker News is about.

      • skrellmOP 6 days ago

        > You should update the page to say that.

        Definitely not. That page is the web service. And if you meant the HN post, that's no place for long explanations either, imho.

        The info you seek is in the README of the repo, where it belongs.

        • gus_massa 5 days ago

          The readme is nice. My suggestion is to write a blog post that includes the two examples in the readme and the example you posted in your comment, and perhaps one or two more (let's say 5 or 6 in total). And post the blog article. I feel if it includes a few use cases and images, it would get more traction.

          • skrellmOP 2 days ago

            > My suggestion is to write a blog post

            Thank you for your kind advice. But the thing is, I'm not a blogger guy, I've never ever written any blog in my life. If you take a look at my repos, you'll see my focus is on writing code.

            Also I honestly don't know what to write.

            I've always though that speeding up page load by shrinking images into indexed images is a common knowledge (smaller page = faster page), never occurred to me this needs explaining. I mean, there are already lots of tools for that (tinypng dot com, ImageMagick, pngquant, etc.), it's just neither can handle APNGs, much less animated WebP, so here's paltool to save the day.

            As for the algorithms, all I've used (weighted color distance and median cut) has a loooong literature, explaining these much better than I could. I did not invent any of it, these are standard image processing algorithms, although I've used some tricks for better performance and some heuristics to increase output quality.

            • gus_massa a day ago

              I was thinking about something simple, like a list of 10 examples with minimal text in between.

              If you meet with a technical friend to drink a beer, and s/he ask what your project can do, which are the 10 coolest examples that you can show?

              ---

              The readme has a few eamples. I'd like a version that shows the explicit command to make the transformation. For example "-D" means decolorize, but I'm not sure how to trigger the recolorize method. Is it "+D"? "-R"? After looking for a while, I think no argument means recolorize but I'm still not sure.

              Also, they show a strange pallete. I'd prefer a version that shows

              1) The original image

              2) The exact pallete (or at least a gif/png that shows the exact squares with the colors of the pallete. For example if the pallete has 8 colors, show a 32x4 image with 8 squares 4x4.)

              3) The command line

              4) The final image

              ---

              Perhaps a few examples that show the dithering vs direct quantization would be nice.

              ---

              Can your program find the optimal pallete? A long time ago I had to transform a color 256^3 image to a 256 colors image. IIRC I used gimp and paint and perhaps a few more programs. But the palette choice was bad and caused too many quirks. I don't remember how I fixed it.

              ---

              A few years ago, my wife wanted a few gif or animals with different colors. I used gimp to find the correct entry in the pallete and then I changed the value of that entry in the pallete directly in the files.

              • skrellmOP an hour ago

                > If you meet with a technical friend to drink a beer, and s/he ask what your project can do, which are the 10 coolest examples that you can show?

                Nothing. This is for those who already understand the benefit of shrinking images and animations using indexed palettes, and just looking for a tool to do it.

                > I'm not sure how to trigger the recolorize method

                You can't, that's not part of the tool. You need to implement it in your app that displays such images. That's the whole point.

                To see recolorization in action, check out one of my other projects here: https://bztsrc.gitlab.io/ludchr/ (select the icons on the right, if a layer has color options, you'll see a pop-up menu with the color variants, clicking on a color will recolorize the layer on-the-fly)

                > Also, they show a strange pallete. I'd prefer a version that shows

                That's exactly what the image shows.

                First figure: original image minus the palette equals decolorized image.

                Second figure: decolorized image plus palette equals multiple colorized outputs.

                The palette can be provided in many formats, but the palette on these figures is the actual palette image I've used with paltool. It is an image of 8 x 4 pixels, so it has 4 different gradients. Out of the 8 possible colors in each gradient only 6 used in the example, so the last 2 colors were replaced with a checkerboard on the preview (in the actual palette image these are fully transparent).

                > A few years ago, my wife wanted a few gif or animals with different colors. I used gimp to find the correct entry in the pallete and then I changed the value of that entry in the pallete directly in the files.

                That's exactly what decolorization and recolorization is for. I needed this for the ludchr project above.

                > Can your program find the optimal pallete?

                No such thing exists, except for pixel art maybe.

                My program uses multiple methods, calculates scores for each (depending on the distance to the original) and picks the one with the best score. Otherwise it is built around the libimagequant library. https://github.com/ImageOptim/libimagequant

                The palette might contain fixed colors, and free slots are filled with quantized colors from the image. If the image has no more different colors than the specified maximum, then yes, the palette will be optimal, otherwise you must make peace with some information loss.

                > A long time ago I had to transform a color 256^3 image to a 256 colors image. IIRC I used gimp and paint and perhaps a few more programs. But the palette choice was bad and caused too many quirks.

                Yes, that's exactly why I've created this tool. I was also struggling with GIMP (unable to handle alpha channel in palettes) and Imagemagick (unable to handle animated PNGs).

                My tool does not reinvent the wheel, it just provides an easy to use interface (CLI as well as a free web-service) around already existing and known to work methods.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection