Last active
September 28, 2015 17:18
-
-
Save nakamura001/1470836 to your computer and use it in GitHub Desktop.
ファイル名にiPhoneの高解像度向け画像のファイル名を表す @2x を付加した名前に変更するスクリプト
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
#! /usr/bin/env python | |
# coding: utf-8 | |
# ファイル名にiPhoneの高解像度向け画像の | |
# ファイル名を表す @2x を付加した名前に変更し、既存の名前で半分の画像ファイルを作成するスクリプト | |
import os,re,sys | |
import tempfile | |
import shutil | |
from PIL import Image | |
import sys | |
try: | |
rootdir = sys.argv[1] | |
print rootdir | |
for (root, dirs, files) in os.walk(rootdir): | |
for f in files: | |
fullpath = os.path.join(root, f) | |
frontpath, ext = os.path.splitext(fullpath) | |
if f[0:1] != "." and (ext.lower() == ".jpg" or ext.lower() == ".png"): | |
print fullpath+"@2x"+ext,fullpath | |
os.rename(fullpath, frontpath+"@2x"+ext) | |
shutil.copyfile(frontpath+"@2x"+ext, fullpath) | |
im = Image.open(fullpath) | |
w, h = im.size | |
w = int(w * .5) | |
h = int(h * .5) | |
im.resize((w, h), Image.ANTIALIAS).save(fullpath) | |
print fullpath | |
except IndexError: | |
print 'input path error.' | |
except IOError: | |
print '"%s" cannot be opened.' % rootdir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment