Image conversion for Android development
I have created simple python script for converting hdpi images into mdpi and ldpi. It converts all png, jpg and gif images in folder, where script is running.
You must have installed PIL module for Python. If you dont want to install PIL module, you can download script with included PIL module.
4: sys.path.append("module")
8: dirList = os.listdir(path)
11: os.mkdir("res/drawable-hdpi")
12: os.mkdir("res/drawable-mdpi")
13: os.mkdir("res/drawable-ldpi")
15: for fname in dirList:
17: outputFile = os.path.splitext(os.path.basename(fname))
19: if (outputFile[1] == ".png" or outputFile[1] == ".jpg" or
20: outputFile[1] == ".gif"):
22: img = Image.open(fname)
25: x = int(img.size[0] * 0.66)
26: y = int(img.size[1] * 0.66)
28: out = img.resize((x, y))
30: outputFile = os.path.splitext(os.path.basename(fname))
32: out.save("res/drawable-mdpi/" + outputFile[0] + "-mdpi" + outputFile[1])
34: x = int(img.size[0] * 0.5)
35: y = int(img.size[1] * 0.5)
37: out = img.resize((x, y))
39: out.save("res/drawable-ldpi/" + outputFile[0] + "-ldpi" + outputFile[1])
41: shutil.move(fname, "res/drawable-hdpi/" +
42: outputFile[0] + "-hdpi" + outputFile[1] )