@Henry(上記のコメント)と同じですが、引数としてPNGファイル名を取り、同じ名前のICNSを出力します。
注: PNGファイル名には、拡張子を区切るための1つのポイント、つまりxpto.pngのみが含まれている必要があります。
(シェルスクリプト用に更新)
したがって、以下のコードをpngファイルがあるフォルダーの「CreateICNS.sh」というファイルに保存し、実行許可を与えます。
コード:
#!/bin/bash
IFS='.' read -ra ADDR <<< "$1"
ICONSET=${ADDR[0]}.iconset
mkdir $ICONSET
sips -z 16 16 $1 --out $ICONSET/icon_16x16.png
sips -z 32 32 $1 --out $ICONSET/icon_16x16@2x.png
sips -z 32 32 $1 --out $ICONSET/icon_32x32.png
sips -z 64 64 $1 --out $ICONSET/icon_32x32@2x.png
sips -z 128 128 $1 --out $ICONSET/icon_128x128.png
sips -z 256 256 $1 --out $ICONSET/icon_128x128@2x.png
sips -z 256 256 $1 --out $ICONSET/icon_256x256.png
sips -z 512 512 $1 --out $ICONSET/icon_256x256@2x.png
sips -z 512 512 $1 --out $ICONSET/icon_512x512.png
cp $1 $ICONSET/icon_512x512@2x.png
iconutil -c icns $ICONSET
rm -R $ICONSET
使い方 :
次に、ターミナルで同じフォルダに「cd」して次のように入力します。
./CreateICNS.sh {PNG filename}
ここで、{PNGファイル名}はPNGファイルの名前、つまりxpto.pngです。
ファイルの名前がabc.pngの場合は、次を使用します。
./CreateICNS.sh abc.png
更新2021-05-20:
私はこれの更新されたバージョンを持っていますが、ここに正しい参照を残すためにどこで見つけたのかわかりません。誰かがこれの所有者であるか、インターネットページのリンクを知っている場合は、クレジットを更新できるようにコメントしてください:
これは完全なbashスクリプトであるため、たとえばpng2icns.sh
、実行権限を付与して保存する必要があります。
次に、を呼び出すpng2icns.sh pngfile1.png
と、16x16〜512x512のすべてのアイコン解像度を含むICNSファイルとiconsetフォルダーが生成されます。
#!/bin/bash
# Creates an icns file from a source image
src_image="$1"
if [ -z "$1" ]; then
echo "No source image was passed to this script"
exit 1
fi
icns_name="$2"
if [ -z "$2" ]; then
icns_name="iconbuilder"
fi
if [ "${src_image:(-3)}" != "png" ]; then
echo "Source image is not a PNG, making a converted copy..."
/usr/bin/sips -s format png "$src_image" --out "${src_image}.png"
if [ $? -ne 0 ]; then
echo "The source image could not be converted to PNG format."
exit 1
fi
src_image="${src_image}.png"
fi
iconset_path="./${icns_name}.iconset"
if [ -e "$iconset_path" ]; then
/bin/rm -r "$iconset_path"
if [ $? -ne 0 ]; then
echo "There is a pre-existing file/dir $iconset_path the could not be deleted"
exit 1
fi
fi
/bin/mkdir "$iconset_path"
icon_file_list=(
"icon_16x16.png"
"icon_16x16@2x.png"
"icon_32x32.png"
"icon_32x32@2x.png"
"icon_128x128.png"
"icon_128x128@2x.png"
"icon_256x256.png"
"icon_256x256@2x.png"
"icon_512x512.png"
"icon_512x512@2x.png"
)
icon_size=(
'16'
'32'
'32'
'64'
'128'
'256'
'256'
'512'
'512'
'1024'
)
counter=0
for a in ${icon_file_list[@]}; do
icon="${iconset_path}/${a}"
/bin/cp "$src_image" "$icon"
icon_size=${icon_size[$counter]}
/usr/bin/sips -z $icon_size $icon_size "$icon"
counter=$(($counter + 1))
done
echo "Creating .icns file from $iconset_path"
/usr/bin/iconutil -c icns "$iconset_path"
if [ $? -ne 0 ]; then
echo "There was an error creating the .icns file"
exit 1
fi
echo "Done"
exit 0