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
[email protected]
[email protected]
[email protected]
Icon29.png
[email protected]
[email protected]
[email protected]
Icon40.png
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
Icon76.png
[email protected]
[email protected]
)
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" : "[email protected]",
"scale" : "2x"
},
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "3x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "3x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "Icon20.png",
"scale" : "1x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "Icon29.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Icon40.png",
"scale" : "1x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Icon76.png",
"scale" : "1x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"size" : "83.5x83.5",
"idiom" : "ipad",
"filename" : "[email protected]",
"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/[email protected]
+ convert /tmp/a.png -resize 40x40 AppIcon.appiconset/[email protected]
+ convert /tmp/a.png -resize 60x60 AppIcon.appiconset/[email protected]
+ convert /tmp/a.png -resize 29x29 AppIcon.appiconset/Icon29.png
+ convert /tmp/a.png -resize 58x58 AppIcon.appiconset/[email protected]
+ convert /tmp/a.png -resize 58x58 AppIcon.appiconset/[email protected]
+ convert /tmp/a.png -resize 87x87 AppIcon.appiconset/[email protected]
+ convert /tmp/a.png -resize 40x40 AppIcon.appiconset/Icon40.png
+ convert /tmp/a.png -resize 80x80 AppIcon.appiconset/[email protected]
+ convert /tmp/a.png -resize 80x80 AppIcon.appiconset/[email protected]
+ convert /tmp/a.png -resize 120x120 AppIcon.appiconset/[email protected]
+ convert /tmp/a.png -resize 120x120 AppIcon.appiconset/[email protected]
+ convert /tmp/a.png -resize 180x180 AppIcon.appiconset/[email protected]
+ convert /tmp/a.png -resize 76x76 AppIcon.appiconset/Icon76.png
+ convert /tmp/a.png -resize 152x152 AppIcon.appiconset/[email protected]
+ convert /tmp/a.png -resize 167x167 AppIcon.appiconset/[email protected]
Done, please output directory: AppIcon.appiconset.

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