Last active
August 29, 2015 14:06
-
-
Save moltak/03a816bc32a60e7d257c to your computer and use it in GitHub Desktop.
안드로이드 이미지 리사이즈
This file contains hidden or 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
#!/usr/bin/python | |
from os import listdir | |
from os.path import isfile, join | |
import os | |
import shutil | |
from PIL import Image | |
import string | |
xxhdpi = './drawable-xxhdpi/' | |
xhdpi = './drawable-xhdpi/' | |
hdpi = './drawable-hdpi/' | |
mdpi = './drawable-mdpi/' | |
def makeDpiFolder(dpi): | |
if os.path.exists(dpi) == False: | |
os.makedirs(dpi) | |
def resizeFile(image_file, dpi, numerator, denominator): | |
print 'resizing ' + image_file | |
im = Image.open(xxhdpi + image_file) | |
width = int(im.size[0] * numerator / denominator) | |
height = int(im.size[1] * numerator / denominator) | |
newim = im.resize((width, height), Image.ANTIALIAS) | |
outfile = dpi + image_file | |
newim.save(outfile, 'PNG') | |
printCopySummary(im, width, height, outfile) | |
def printCopySummary(im, width, height, outfile): | |
print ("%s w: %d->%d h: %d->%d" % (outfile, im.size[0], width, im.size[1], height)) | |
makeDpiFolder(xhdpi) | |
makeDpiFolder(hdpi) | |
makeDpiFolder(mdpi) | |
onlyfiles = [f for f in listdir(xxhdpi) if isfile(join(xxhdpi,f))] | |
copycount = 0 | |
for f in onlyfiles: | |
file_extension = f.split('.')[1] | |
if (string.upper(file_extension) == 'PNG') | (file_extension == '9'): | |
resizeFile(f, xhdpi, 2, 3) | |
resizeFile(f, hdpi, 1, 2) | |
resizeFile(f, mdpi, 1, 3) | |
copycount += 1 | |
print ('\ndone: %d files' % copycount) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment