Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JackJuly committed Apr 18, 2021
0 parents commit 145c391
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
Binary file added IconTool.dmg
Binary file not shown.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# png2icns
English | [中文](README_zh_CN.md)


A shell script and an app are provided for you to easily
generate an icns file with a png image in macOS.

## Notice

Both tools use built-in tools in the terminal in macOS.
You can check these paths below to see if they are already exist and executable.

```
sips: /usr/bin/sips
iconutil: /usr/bin/iconutil
```

The size of your source image should be suitable for an icon, which is better to be 1024x1024 pixels.
The `sample.png` is provided for testing.

## Usage

### 1. png2icns.sh
Simply run the `png2icns.sh` and then **specify** the path to your source png image. The icns flie will be generated and saved on your **desktop**.

```
$ cd png2icns
$ chmod u+x png2icns.sh
$ ./png2icns.sh
Please enter the path to your source PNG image: [path your source png]
```

### 2. IconTool.app
Open the dmg file, then drag the `IconTool.app` to Applications and click to run.
Just simply choose a png image and the icns flie will be generated and saved on your **desktop**.
This app is created using the `Automator.app` in macOS.

35 changes: 35 additions & 0 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# png2icns
[English](README.md) | 中文


这里提供了两种工具*(shell脚本和app)*可帮助你在macOS系统上轻松的将一个png图标生成为.icns的图标文件。

## 注意事项

这两个工具均使用了macOS系统内置的工具进行格式转换。你可以在系统中事先检查以下两个工具是否存在并且可被执行。

```
sips: /usr/bin/sips
iconutil: /usr/bin/iconutil
```

源png图片应尺寸合适且清晰,最好为1024x1024像素大小。
这里提供了一个`sample.png`可用来测试。

## 使用方法

### 1. png2icns.sh
只需简单地运行`png2icns.sh`脚本,并**指定**源png图片的路径,生成的.icns文件将会被保存在你的**桌面**

```
$ cd png2icns
$ chmod u+x png2icns.sh
$ ./png2icns.sh
Please enter the path to your source PNG image: [path your source png]
```

### 2. IconTool.app
打开dmg镜像文件,将`IconTool.app`拖入到应用程序中,点击运行即可。
选择好源png文件后程序自动运行,生成的.icns文件将会被保存在你的**桌面**
此app是由macOS中自带的`Automator.app(自动操作)`创建。

55 changes: 55 additions & 0 deletions png2icns.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#! /bin/bash

if [ ! -x "/usr/bin/sips" ]; then
echo "失败:未找到可执行的SIPS "
echo "Failed: Cannot find required SIPS executable at: /usr/bin/sips "
exit;
fi
if [ ! -x "/usr/bin/iconutil" ]; then
echo "失败:未找到可执行的ICONUTIL "
echo "Failed: Cannot find required ICONUTIL executable at: /usr/bin/iconutil "
exit;
fi

read -p "Please enter the path to your source PNG image:" FILENAME

if [ ! -f "${FILENAME}" ]; then
echo "失败:图片未找到!"
echo "Failed: Image Not Found!"
exit;
fi


if [[ $FILENAME == *.png ]];then

DIRNAME='icon-'`date +"%Y-%m-%d-%H:%M:%S"`
cd /tmp
mkdir $DIRNAME
cd $DIRNAME
cp $FILENAME icon.png

mkdir icon.iconset

sips -z 16 16 icon.png --out icon.iconset/icon_16x16.png
sips -z 32 32 icon.png --out icon.iconset/[email protected]
sips -z 32 32 icon.png --out icon.iconset/icon_32x32.png
sips -z 64 64 icon.png --out icon.iconset/[email protected]
sips -z 128 128 icon.png --out icon.iconset/icon_128x128.png
sips -z 256 256 icon.png --out icon.iconset/[email protected]
sips -z 256 256 icon.png --out icon.iconset/icon_256x256.png
sips -z 512 512 icon.png --out icon.iconset/[email protected]
sips -z 512 512 icon.png --out icon.iconset/icon_512x512.png
sips -z 1024 1024 icon.png --out icon.iconset/[email protected]

iconutil -c icns icon.iconset

cp icon.icns ~/desktop/$DIRNAME.icns
cd ..
rm -rf $DIRNAME
echo "图标已保存至桌面!"
echo "The icon is now on your desktop!"

else
echo "注意:请使用PNG格式的文件!"
echo "Error: Source image format should be PNG!"
fi
Binary file added sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 145c391

Please sign in to comment.