Saturday, May 31, 2014

Simple command-line utility to replace colors in multiple bitmap images

In this post I will show a very basic utility (the source is about 15 lines of code written in less than 5 minutes) to do a very specific task.
Some weeks ago, for school, I had to print and study two PowerPoint presentations of about 20 slides each, that for some strange reason had an intense pink background, so that printing them would be resulted in a useless waste of printer's ink (if I had printed in colors, the magenta ink, and if I had printed in black and white, the black ink since the background would have become gray). To avoid this, I wanted to change the background to white, that would have been very easy if I had the PPT file, but I only had a PDF-exported version of both presentations. I made some searches on the web about how to edit a pdf to change the colors, but I haven't found anything of useful. So I focused on working on images, since converting a pdf to images is very easy (lots of programs can do that, for example I used the free PDF-XChange Viewer) and editing images is a lot simpler than working on PDF documents. The result of the conversion was an image for each page. After that, on a single image, the editing operation I needed to do could have been done very easily with image manipulation applications such as gimp; but since performing the modification on each of the about 40 images wouldn't have been very time-saving, I decided to write, using Visual Basic .NET, an utility to automatize the process.
You may consider it a stupid program for its simplicity, but I'm publishing it so if someone has to do a task like the one I described before, he will found the ready to use solution, surely better than manually editing each single image.


Binary (only .exe file)    or    Source(source archive)

What this program does is simply to replace, for each image in the input folder, each pixel that has the color of the pixel in the (0, 0) coordinates with a white pixel, and then save the result to the output folder. It takes the (0, 0) pixel because it's designed to remove the background, but it's very easy to change it by editing the source file (you need the source archive to do it).