The Toad's Batchroom

Useful Python scripts for every day

The Toad's Batchroom repository includes various Python scripts for batch processing. Total number of files varies over time.

Good news everyone: new program added, named Sanctifier. As can be easily guessed from its name, this program is intended for converting a set of PNG files into a single Windows Icon (.ICO) file containing multiple icons of different sizes. Multiple image single compressed ICO files thus obtained are suitable for different purposes, from adding icons to your programs (which is of special interest for Python developers due to lack of native icon building tools) to assigning meaningful and recognizable icons to your personal folders via desktop.ini.

PNG Sanctifier: a PNG to multisize ICO converter (click for details)

Surely you can use GIMP to open a bunch of PNGs as layers, then export resulting image as an icon. Unfortunately, it means that GIMP really opens an image, and then saves it, that is, first decompresses, then compresses image using GIMP general purpose compression library, which is definitely not the best in terms of compression efficiency.

The main idea, and a sole reason for Sanctifier development, is that this program does not open images at all. Instead, it transfers PNG data, already compressed, into Windows ICO skeleton "as is". This allows using efficient PNG optimizers before assembling icons, and then building icons that retain the best compression possible.

Suggested workflow is as following:

  • Create a set of images (according to Microsoft "Icons (Design basics): Size requirements", 16, 32, 48 and 256 pixel sizes seem to form a minimal set, although adding 20, 24, 40, 64 and 96 px is often recommended), and save a copies of your images as PNG files in one folder.
  • Run a PNG optimizer on these files (I personally recommend oxipng).
  • Start Sanctifier.py. Immediately a file "Open" dialog, allowing multiple file selection, will pop up. Browse for a folder above and select all PNG files intended to be used for icon construction at once.
    Sanctifier GUI screenshot
  • If necessary, change icon images order by changing file order in file list by selecting a file name and pressing Ctrl+Up or Ctrl+Down to move selected item up or down; Ctrl+I fully inverts the list order.
  • Once satisfied with file list order, press Enter; standard file "Save as" dialog will pop up. Use it to save your icon.
  • If you feel like assembling one more icon, press Ctrl+O to open new file list.
  • Once finished, don't forget to prevent global warming and exit Sanctifier by pressing Ctrl+Q or Ctrl+W.

According to my test results, oxipng gives up to 10% savings for photo-like 256×256 px PNGs; for geometrical drawings savings are unpredictable because PNG compression is especially efficient.

For a small images, like 16×16 px, compression benefit is expected to be smaller, but total size benefit of ca. 5% for a whole .ICO file may be counted on.

Ok, that's the end of our scientists report on "Sanctifier".

Let's go back to old frequently used and thoroughly checked scripts.

Most useful ones appeared to be:

Note that programs dir COMPACT LZX, dir OPTIVORBIS ogg, dir ffmpeg flac2ogg 48 and dir ffmpeg flac2ogg 44 accept command line arguments at start time. Argument is supposed to be a name of folder; in this case program GUI opens right in this folder. If argument happen to be a file, GUI will be opened in folder containing it. You may use it for creating shortcuts like:

pythonw.exe "dir COMPACT LZX.py" "%1"

(using actual addresses of Python and script on your system, of course) and then simply drag-and-drop folders onto shortcut to open program right where you need it. If argument is absent (e.g., you just double-click program), program simply opens in default directory and wait for you to browse and point to required location.

COMPACT LZX Starting GUI COMPACT LZX Busy GUI

Note that since these batch scripts are made for my personal use, they are spontaneously updated without notification.

Proceed to Batchfiles at GitHub for downloads...

...or Move back to Dnyarri`s Python freeware main page.