Because I got ICO files and I want them in PNG.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os, glob

# location of the files
sourceDir = "/media/yamazaki/Work/Pictures/Icons/KidsXP/"
# output directory
targetDir = "/tmp/kidsxp_png/"
# the real processor of this script: imagemagick 
convertCmd = "convert %s[9] -resize %s %s"
# which categories to process? all of 'em?
processDirs = ("actions", "apps", "devices", "filesystems", "mimetypes")
# extract it and move into known usable sizes 
knownSizes = ('16x16', '22x22', '32x32', '48x48', '64x64', '96x96', '128x128')

def processDir(path, thissize):
  print "Processing source path : %s" % path
  dummy, category = os.path.split(path)

  for item in glob.glob(path + '/*.ico'):
    dummy, itemName = os.path.split(item)
    tgtDir = os.path.join(targetDir, thissize, category, '')
    tgtName = itemName[:-3] + 'png' # "xyz.ico" filename to "xyz.png"
    print "Writing %20s -> %s" % (itemName, tgtDir + tgtName)
    if not os.path.exists(tgtDir):
    cmd = convertCmd % (item, thissize, tgtDir + tgtName)
    # execute
    os.system(cmd)  # ooh! the horror!!

for item in processDirs:
  s = sourceDir + item
  if os.path.isdir(s):
    for size in knownSizes:
      processDir(s, size)
    print "Skipping %s" % (s)

Leave a comment

Filed under Ilmu

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s