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):
os.makedirs(tgtDir)
cmd = convertCmd % (item, thissize, tgtDir + tgtName)
# execute
os.system(cmd) # ooh! the horror!!
##
print
##
for item in processDirs:
s = sourceDir + item
if os.path.isdir(s):
for size in knownSizes:
processDir(s, size)
else:
print "Skipping %s" % (s)
##
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.