Adding new image assets to our Android app is tedious. Since our designers target iOS first, there are a few things the Android team has to do when we get new graphics:

  1. Ensure graphics have valid file names (no hyphens, no unnecessary @2x in the name).
  2. Ensure similar graphics (e.g. icons in the drawer) are the same size.
  3. Provide the graphic at all possible densities.

I’ve created a script to speed up the renaming process. Before running it, I only copy the retina (…@2x…) graphics to my working directory, and then run it on my Mac or Linux machine:


# Standardizes image file names to be usable as Android resources.

# Make sure we have some files to rename before continuing
if [ -z "$1" ]; then
	echo "usage: file [file2...]"
	exit 1

for INFILE; do
	# Do the stuff
	if [ "$INFILE" != "${INFILE//-/_}" ]; then
		# Replace hyphens with underscores
		mv -i "$INFILE" "$NEWFILE"

	if [ "$NEWFILE" != "${NEWFILE//@2x/}" ]; then
		# Remove retina-ified filenames
		mv -i "$NEWFILE" "${NEWFILE//@2x/}"

	# Sanity check
	echo "Moved $INFILE to ${NEWFILE//@2x/}"

Also on GitHub.

This is useful for doing multiple images at once, e.g. icon-*.png, and, of course, it helps when you like the designer’s naming scheme.

$ logout