Last active
August 29, 2015 14:20
-
-
Save YusukeIwaki/ac806165d1ddcf131c0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
from glob import glob | |
from PIL import Image | |
import sys | |
TRANSPARENT=(255,255,255,0) | |
BLACK=(0,0,0) | |
d=dict() | |
#d["tooltip_background_left.9.png"]=((22,24),(16,18),(5,25),(14,20)) | |
d["tooltip_background_top.9.png"]=((16,18),(28,30),(14,18),(7,32)) | |
d["card_background.9.png"]=((4,6),(4,6),(4,7),(4,7)) | |
def parse(s): | |
return [int(x,10) for x in s.strip().split("-")] | |
def edit(filename,scale): | |
img=Image.open(filename) | |
pix=img.load() | |
w,h=img.size | |
k="dpi/" | |
idx=filename.find(k) | |
key=filename[idx+len(k):] | |
if not d.has_key(key): return | |
#initialize | |
for i in xrange(0,w): | |
pix[(i,0)]=TRANSPARENT | |
pix[(i,h-1)]=TRANSPARENT | |
for i in xrange(0,h): | |
pix[(0,i)]=TRANSPARENT | |
pix[(w-1,i)]=TRANSPARENT | |
#left | |
start,end = [int(x*scale) for x in d[key][0]] | |
for i in xrange(start,end+1): | |
pix[(0,i)]=BLACK | |
#top | |
start,end = [int(x*scale) for x in d[key][1]] | |
for i in xrange(start,end+1): | |
pix[(i,0)]=BLACK | |
#right | |
start,end = [int(x*scale) for x in d[key][2]] | |
for i in xrange(start,end+1): | |
pix[(w-1,i)]=BLACK | |
#bottom | |
start,end = [int(x*scale) for x in d[key][3]] | |
for i in xrange(start,end+1): | |
pix[(i,h-1)]=BLACK | |
img.save(filename) | |
for filename in glob("drawable-mdpi/*.9.png"): | |
edit(filename,1.0) | |
for filename in glob("drawable-hdpi/*.9.png"): | |
edit(filename,1.5) | |
for filename in glob("drawable-xhdpi/*.9.png"): | |
edit(filename,2.0) | |
for filename in glob("drawable-xxhdpi/*.9.png"): | |
edit(filename,3.0) | |
for filename in glob("drawable-xxxhdpi/*.9.png"): | |
edit(filename,4.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
from glob import glob | |
import os | |
suffix_list=("-mdpi","-hdpi","-xhdpi","-xxhdpi","-xxxhdpi") | |
d=dict() | |
d["tooltip_background_left"]="tooltip_background_left.9" | |
for s in suffix_list: | |
cmd="mkdir -p ./drawable"+s | |
print cmd | |
os.system(cmd) | |
for filename in glob("*.png"): | |
for suf in suffix_list: | |
s=suf+".png" | |
if filename.endswith(s): | |
cmd = "cp %s drawable%s/%s.png"%(filename.replace(" ","\\ "),suf,d[filename[:-len(s)]]) | |
print cmd | |
os.system(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment