Requirements:
- Python for Windows
- Python windows32 extensions (both free and easy to do)
Notes:
- You cannot export icons in this (yet)
- Don't blame me for errors
- SAVE YOUR WORK BEFOREHAND I AM NOT RESPONSIBLE FOR DESTROYING THE UNIVERSE!
import win32com.client | |
psApp = win32com.client.Dispatch("Photoshop.Application") | |
print "Please make sure you have the current document open and saved in the base of your project as we're going to save it by dpi NOW." | |
print "You also need the document in 320dpi for this to work properly!" | |
try: | |
var = input("Press enter") | |
except: | |
pass | |
import os | |
doc = psApp.Application.ActiveDocument | |
width = doc.Width | |
height = doc.Height | |
base = os.path.dirname(doc.FullName) | |
name = ".".join( doc.Name.split(".")[0:-1] ) | |
print "Document has ", width, "x", height | |
print name, base | |
print "Now to export the document into correct locations" | |
print "1. XHDPI" | |
path = os.path.join(base, "res", "drawable-xhdpi"); | |
try: | |
os.makedirs(path) | |
except: | |
pass | |
options = win32com.client.Dispatch("Photoshop.PNGSaveOptions") | |
doc.SaveAs(os.path.join(path, name + ".png"), options, True) | |
print "2. HDPI" | |
path = os.path.join(base, "res", "drawable-hdpi") | |
try: | |
os.makedirs(path) | |
except: | |
pass | |
doc.ResizeImage(width, height, 240) | |
doc.SaveAs(os.path.join(path, name + ".png"), options, True) | |
print "3. MDPI" | |
path = os.path.join(base, "res", "drawable-mdpi") | |
try: | |
os.makedirs(path) | |
except: | |
pass | |
doc.ResizeImage(width, height, 160) | |
doc.SaveAs(os.path.join(path, name + ".png"), options, True) | |
print "4. LDPI" | |
path = os.path.join(base, "res", "drawable-ldpi") | |
try: | |
os.makedirs(path) | |
except: | |
pass | |
doc.ResizeImage(width, height, 120) | |
doc.SaveAs(os.path.join(path, name + ".png"), options, True) | |
var = input("Press enter to continue") |