Skip to content

Instantly share code, notes, and snippets.

@scue
Last active March 7, 2019 08:35
Show Gist options
  • Save scue/a545606760085a6e3fac01e232b67cda to your computer and use it in GitHub Desktop.
Save scue/a545606760085a6e3fac01e232b67cda to your computer and use it in GitHub Desktop.
iOS应用程序图标(AppIcon.appiconset)快速制作脚本
#!/bin/sh
# PNG2AppIcon-iOS.sh
#
#
# Created by scue on 2019/3/7.
#
img_names=(
Icon1024.png
Icon20.png
Icon20@2x-1.png
Icon20@2x.png
Icon20@3x.png
Icon29.png
Icon29@2x-1.png
Icon29@2x.png
Icon29@3x.png
Icon40.png
Icon40@2x-1.png
Icon40@2x.png
Icon40@3x.png
Icon60@2x.png
Icon60@3x.png
Icon76.png
Icon76@2x.png
Icon83.5@2x.png
)
img_sizes=(
1024x1024
20x20
40x40
40x40
60x60
29x29
58x58
58x58
87x87
40x40
80x80
80x80
120x120
120x120
180x180
76x76
152x152
167x167
)
set -e
if [[ $# -lt 1 ]]; then
echo "usage: $0 <file.png>"
exit 1
fi
input=$1
output=AppIcon.appiconset
mkdir ${output}
# step 1: convert png
index=0
for name in ${img_names[@]}; do
size=${img_sizes[index]}
(
set -x
convert ${input} -resize ${size} ${output}/${name}
)
((index++))
done
# step 2: generate Contents.json
echo "create ${output}/Contents.json"
cat <<'EOF' > ${output}/Contents.json
{
"images" : [
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "Icon20@2x.png",
"scale" : "2x"
},
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "Icon20@3x.png",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon29@2x.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon29@3x.png",
"scale" : "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Icon40@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Icon40@3x.png",
"scale" : "3x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Icon60@2x.png",
"scale" : "2x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Icon60@3x.png",
"scale" : "3x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "Icon20.png",
"scale" : "1x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "Icon20@2x-1.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "Icon29.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "Icon29@2x-1.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Icon40.png",
"scale" : "1x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Icon40@2x-1.png",
"scale" : "2x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Icon76.png",
"scale" : "1x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Icon76@2x.png",
"scale" : "2x"
},
{
"size" : "83.5x83.5",
"idiom" : "ipad",
"filename" : "Icon83.5@2x.png",
"scale" : "2x"
},
{
"size" : "1024x1024",
"idiom" : "ios-marketing",
"filename" : "Icon1024.png",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
EOF
echo "Done, please output directory: ${output}."
#convert ${filename} -resize $size ${dirname}/${pdfname}
@scue
Copy link
Author

scue commented Mar 7, 2019

运行结果:

/tmp/PNG2AppIcon-iOS.sh /tmp/a.png
+ convert /tmp/a.png -resize 1024x1024 AppIcon.appiconset/Icon1024.png
+ convert /tmp/a.png -resize 20x20 AppIcon.appiconset/Icon20.png
+ convert /tmp/a.png -resize 40x40 AppIcon.appiconset/Icon20@2x-1.png
+ convert /tmp/a.png -resize 40x40 AppIcon.appiconset/Icon20@2x.png
+ convert /tmp/a.png -resize 60x60 AppIcon.appiconset/Icon20@3x.png
+ convert /tmp/a.png -resize 29x29 AppIcon.appiconset/Icon29.png
+ convert /tmp/a.png -resize 58x58 AppIcon.appiconset/Icon29@2x-1.png
+ convert /tmp/a.png -resize 58x58 AppIcon.appiconset/Icon29@2x.png
+ convert /tmp/a.png -resize 87x87 AppIcon.appiconset/Icon29@3x.png
+ convert /tmp/a.png -resize 40x40 AppIcon.appiconset/Icon40.png
+ convert /tmp/a.png -resize 80x80 AppIcon.appiconset/Icon40@2x-1.png
+ convert /tmp/a.png -resize 80x80 AppIcon.appiconset/Icon40@2x.png
+ convert /tmp/a.png -resize 120x120 AppIcon.appiconset/Icon40@3x.png
+ convert /tmp/a.png -resize 120x120 AppIcon.appiconset/Icon60@2x.png
+ convert /tmp/a.png -resize 180x180 AppIcon.appiconset/Icon60@3x.png
+ convert /tmp/a.png -resize 76x76 AppIcon.appiconset/Icon76.png
+ convert /tmp/a.png -resize 152x152 AppIcon.appiconset/Icon76@2x.png
+ convert /tmp/a.png -resize 167x167 AppIcon.appiconset/Icon83.5@2x.png
Done, please output directory: AppIcon.appiconset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment