I wrote a small little script when the designers only give me files that are made for iOS with the silly name ending such as @3x.png. According to the scaling guidelines in iOS and Android they should fit pretty nicely without demanding that the designer create new graphics (which they will most likely complain and not do). @3x goes into xxhdpi, @2x goes into xhdpi and @1x goes into mdpi.

It’s available below but also on GitHub gists here:

https://gist.github.com/davols/3bd1c874a351dcb95308

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python
# -*- coding: utf-8 -*-

import argparse
import os
import shutil

'''
call with a path that contains files that are named
according to iOS format. Renames and moves the files
into corresponding folder.
./arenamer.py -p files (-d optional, remove original file)

'''


def walkdirectory(directory, delete):
    dirs = os.listdir(directory)
    os.mkdir('%s/mdpi' % directory)
    os.mkdir('%s/xhdpi' % directory)
    os.mkdir('%s/xxhdpi' % directory)
    for filen in dirs:
        if filen.endswith('@1x.png'):
            newDir = '%s/mdpi' % directory
            newFileName = filen.replace('@1x.png', '.png')
            shutil.copy('%s/%s' % (directory, filen),
                        '%s/%s' % (newDir, newFileName))
            if delete:
                os.remove('%s/%s' % (directory, filen))
        elif filen.endswith('@2x.png'):
            newFileName = filen.replace('@2x.png', '.png')
            newDir = '%s/xhdpi' % directory
            shutil.copy('%s/%s' % (directory, filen),
                        '%s/%s' % (newDir, newFileName))
            if delete:
                os.remove('%s/%s' % (directory, filen))
        elif filen.endswith('@3x.png'):
            newDir = '%s/xxhdpi' % directory
            newFileName = filen.replace('@3x.png', '.png')
            shutil.copy('%s/%s' % (directory, filen),
                        '%s/%s' % (newDir, newFileName))
            if delete:
                os.remove('%s/%s' % (directory, filen))
    print 'Done'

parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('-p', '--path',  action='store', dest='path',
                    help='Path for the images')
parser.add_argument('-d', '--delete', dest='delete', action='store_true')
args = parser.parse_args()
if args.path is not None:
    print 'Path: %s' % args.path
    walkdirectory(args.path, args.delete)
else:
    print 'You need to write a path'