Last active
April 30, 2023 16:51
-
-
Save SimplyKyra/a1aaa5925a24892acc35383d2654adf2 to your computer and use it in GitHub Desktop.
Bash script that takes in an image, confirms its square, and creates seven resized images matching what Apple needs for its app icons. Names each to reflect its new size. Blog post to come.
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
#!/bin/bash | |
# Run as: ./createAppIcons.sh filename | |
# Assumes you are running the script where you want it to execute. | |
# If you want a different size you just need to add a line, or edit one, at the bottom of the file. | |
if [ $# -ne 1 ]; then | |
echo "Please call this script with one argument - the image file you want to resize." | |
exit 1 | |
fi | |
echo -e "\nWorking in directory: $PWD\nWorking on file: $1\n" | |
# Checks to see the condition returned and if failed exits he program | |
if [ ! -f "$1" ]; then | |
echo "Couldn't access the file specified. Exiting." | |
exit 1 | |
fi | |
echo "Checking dimensions of image: $1" | |
width=$(identify -format '%w' "$1" ) | |
height=$(identify -format '%h' "$1") | |
if [ $width -ne $height ]; then | |
echo "Image is not a square! It's height is $height and width is $width." | |
echo "Exiting program. Please fix and run this again." | |
exit 1 | |
fi | |
echo "Image is a square so about to run the script on file: $1" | |
# This currently outputs seven square files. If you want to add another size | |
# to the output copy and paste one of the below lines and edit it to the size. | |
# For example in the line: magick "$1" -resize 16x16 "16 - $1" | |
# 16x16 specifies the size of the new file | |
# "16 - $1" specifies the name of the file where $1 is the original filename | |
# So if your input is a file name myImg adding a line saying | |
# magick "$1" -resize 10x10 "OTHER - $1" | |
# Would output a file of size 10 by 10 pixels whose name is OTHER - myImg | |
magick "$1" -resize 1024x1024 "1024 - $1" | |
magick "$1" -resize 512x512 "512 - $1" | |
magick "$1" -resize 256x256 "256 - $1" | |
magick "$1" -resize 128x128 "128 - $1" | |
magick "$1" -resize 64x64 "64 - $1" | |
magick "$1" -resize 32x32 "32 - $1" | |
magick "$1" -resize 16x16 "16 - $1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment