Skip to content

Instantly share code, notes, and snippets.

@brendanjcaffrey
Created December 25, 2012 17:00
Show Gist options
  • Save brendanjcaffrey/4374212 to your computer and use it in GitHub Desktop.
Save brendanjcaffrey/4374212 to your computer and use it in GitHub Desktop.
A little bash script that takes a bunch of retina sized images, moves them to image@2x.png and then creates a half size version using imagemagick.
#!/bin/bash
# loops through a directory of files, moves all .png files to file@2x.png
# and then resizes it using imagemagick to 50% size in file.png
shopt -s nullglob # if there are no .png files in the directory, then the below line won't just return *.png
ext=png
for file in *.$ext
do
text="${file##*.}"
name="${file%.*}"
new=$name@2x.$ext
if ["$text"="$ext"]
then
mv $file $new
convert $new -resize 50% $file
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment