xcode 如何使用iconutil手动创建icns文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12306223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to manually create icns files using iconutil?
提问by Blue
When I'm validating my app I get this error:
当我验证我的应用程序时,我收到此错误:
the application bundle does not contain an icon in ICNS format, containing both a
512x512
and a512x512@2x
image.
应用程序包不包含 ICNS 格式的图标,包含 a
512x512
和512x512@2x
图像。
I use to make the icns icons with Img2icnsapp and until today it always worked properly. But now I'm getting that error and there's no way to make it work. I tried to put two PNG files together (512x512
and 1024x1024
) in Img2icnsbut I always get that error. I also tried to follow the instructions in Apple's OS X Human Interface Guideline but when I try to make the icon sets I get this terminal error:
我过去常常使用Img2icns应用程序制作icns图标,直到今天它始终正常工作。但是现在我遇到了那个错误并且没有办法让它工作。我试图在Img2icns 中将两个 PNG 文件放在一起(512x512
和1024x1024
),但我总是得到那个错误。我还尝试按照 Apple 的 OS X 人机界面指南中的说明进行操作,但是当我尝试制作图标集时,出现此终端错误:
-bash: syntax error near unexpected token 'newline'
-bash:意外标记“换行符”附近的语法错误
I am not very good with terminal commands so maybe I'm doing something wrong. I wrote:
我不太擅长终端命令,所以也许我做错了什么。我写:
iconutil -c icns </Users/myname/SDK Mac Apps/MyApp/grafica/icon.iconset>
If anyone could help it would be very much appreciated. Thanks, Massy.
如果有人可以提供帮助,将不胜感激。谢谢,马西。
采纳答案by Anne
Checkout the following instructions (link):
查看以下说明(链接):
Use iconutil to Create an icns File Manually
The
iconutil
command-line tool convertsiconset
folders to deployment-ready, high-resolution icns files. (You can find complete documentation for this tool by enteringman iconutil
in Terminal.) Using this tool also compresses the resultingicns
file, so there is no need for you to perform additional compression.To convert a set of icons to an icns file
Enter this command into the Terminal window:
iconutil -c icns <iconset filename>
where
<iconset filename>
is the path to the folder containing the set of icons you want to convert toicns
. The output is written to the same location as theiconset file
, unless you specify an output file as shown:
iconutil -c icns -o <icon filename> <iconset filename>
使用 iconutil 手动创建 icns 文件
该
iconutil
命令行工具转换iconset
文件夹部署就绪,高分辨率的谘询网络文件。(您可以通过man iconutil
在终端中输入来找到此工具的完整文档。)使用此工具还会压缩生成的icns
文件,因此您无需执行额外的压缩。将一组图标转换为 icns 文件
在终端窗口中输入此命令:
iconutil -c icns <iconset filename>
<iconset filename>
包含要转换为的图标集的文件夹的路径在哪里icns
。输出将写入与 相同的位置iconset file
,除非您指定输出文件,如下所示:
iconutil -c icns -o <icon filename> <iconset filename>
In other words, you need to replace <iconset filename>
by the path:
换句话说,您需要<iconset filename>
按路径替换:
/Users/myname/SDK Mac Apps/MyApp/grafica/icon.iconset
Since the path contains spaces, you need to use double quotes, for example:
由于路径包含空格,所以需要使用双引号,例如:
iconutil -c icns "/Users/myname/SDK Mac Apps/MyApp/grafica/icon.iconset"
This command should work properly.
这个命令应该可以正常工作。
回答by Aidan
Here's a script to convert a 1024x1024 png (named "Icon1024.png") to the required icns file. Save it to a filed called "CreateICNS.src" in the folder where your png file is then in terminal "cd" to the same folder and type "source CreateICNS.src" to call it:
这是一个将 1024x1024 png(名为“Icon1024.png”)转换为所需 icns 文件的脚本。将其保存到文件夹中名为“CreateICNS.src”的文件中,然后在终端“cd”中将其保存到同一文件夹中,然后键入“source CreateICNS.src”来调用它:
mkdir MyIcon.iconset
sips -z 16 16 Icon1024.png --out MyIcon.iconset/icon_16x16.png
sips -z 32 32 Icon1024.png --out MyIcon.iconset/[email protected]
sips -z 32 32 Icon1024.png --out MyIcon.iconset/icon_32x32.png
sips -z 64 64 Icon1024.png --out MyIcon.iconset/[email protected]
sips -z 128 128 Icon1024.png --out MyIcon.iconset/icon_128x128.png
sips -z 256 256 Icon1024.png --out MyIcon.iconset/[email protected]
sips -z 256 256 Icon1024.png --out MyIcon.iconset/icon_256x256.png
sips -z 512 512 Icon1024.png --out MyIcon.iconset/[email protected]
sips -z 512 512 Icon1024.png --out MyIcon.iconset/icon_512x512.png
cp Icon1024.png MyIcon.iconset/[email protected]
iconutil -c icns MyIcon.iconset
rm -R MyIcon.iconset
回答by Neurotransmitter
While using all kinds of scripts to convert hi-res PNG
image to a pleiad of different low-resolution copies may seem handy (and it really is), one should not forget that this kind of automatic resizing will render perceptibly imperfect images.
虽然使用各种脚本将高分辨率PNG
图像转换为一组不同的低分辨率副本似乎很方便(而且确实如此),但不应忘记这种自动调整大小会呈现明显不完美的图像。
Lesser the resolution, blurrier the icon!
分辨率越低,图标越模糊!
Instead, you should always request a logo in some vector format from your designer, for example in SVG
. With this on hand, you can manually prepare perfect PNG
files in all required resolutions and then make a single .icns
file, which will make your app icon look beautiful on every single screen, from a cheap iPhone SE to some high-end Retina display of the latest iMac. You can use Photoshop, GIMP or any other tool of your choice to generate these icons.
相反,您应该始终从您的设计师那里请求某种矢量格式的徽标,例如SVG
. 有了这个,您可以手动准备PNG
所有所需分辨率的完美文件,然后制作一个.icns
文件,这将使您的应用程序图标在每个屏幕上看起来都很漂亮,从廉价的 iPhone SE 到最新的高端 Retina 显示屏iMac。您可以使用 Photoshop、GIMP 或您选择的任何其他工具来生成这些图标。
From the latest Apple's Human Interface Guidelinesas of 2020, you should prepare the following PNG
files:
从2020 年最新的Apple 人机界面指南中,您应该准备以下PNG
文件:
+---------------------+--------------------+--------------+
| filename | resolution, pixels | density, PPI |
+---------------------+--------------------+--------------+
| icon_16x16.png | 16x16 | 72 |
| [email protected] | 32x32 | 144 |
| icon_32x32.png | 32x32 | 72 |
| [email protected] | 64x64 | 144 |
| icon_128x128.png | 128x128 | 72 |
| [email protected] | 256x256 | 144 |
| icon_256x256.png | 256x256 | 72 |
| [email protected] | 512x512 | 144 |
| icon_512x512.png | 512x512 | 72 |
| [email protected] | 1024x1024 | 144 |
+---------------------+--------------------+--------------+
After all the PNG files are prepared, place them into some directory with .iconset
extension (Logos.iconset
for example) and execute the following from the Terminal
:
准备好所有 PNG 文件后,将它们放入某个带有.iconset
扩展名的目录中(Logos.iconset
例如),然后从 执行以下命令Terminal
:
iconutil --convert icns Logos.iconset
If there were no errors after executing this command, then all the files were processed properly, and you got the Logos.icns
file in the same directory, containing all the beautiful crisp logos for your app which will suit any modern screen.
如果执行此命令后没有错误,则所有文件都已正确处理,并且您将Logos.icns
文件放在同一目录中,其中包含适合任何现代屏幕的应用程序的所有漂亮清晰的徽标。
回答by Zeke
There's a command-line node module that does all the work of converting a PNG file into an iconset directory:
有一个命令行节点模块可以完成将 PNG 文件转换为 iconset 目录的所有工作:
npm install -g node-icns
nicns --in adventure-cat.png --out adventure-cat.icns
回答by Aidan
These commands (entered in Terminal) worked for me to convert an old icns file to the new format:
这些命令(在终端中输入)对我有用,可以将旧的 icns 文件转换为新格式:
cd Folder_With_Icns_File
iconutil -c iconset Your_Icon_Name.icns
rm Your_Icon_Name.icns
iconutil -c icns Your_Icon_Name.iconset
rm -R Your_Icon_Name.iconset
Update
更新
The -c
parameter to iconutil is no longer supported. Use --convert
instead:
-c
不再支持 iconutil的参数。使用--convert
来代替:
cd Folder_With_Icns_File
iconutil --convert iconset Your_Icon_Name.icns
rm Your_Icon_Name.icns
iconutil --convert icns Your_Icon_Name.iconset
rm -R Your_Icon_Name.iconset
回答by Bearsu
Additional comment, when you create .icns file, you need to rename all the pic files with prefix "icon_", otherwise, iconutil will fail with error message: ".iconset:error: Failed to generate ICNS." which is not informative at all.
补充说明,当你创建.icns 文件时,你需要重命名所有带有前缀“icon_”的图片文件,否则iconutil 将失败并显示错误消息:“.iconset:error: Failed to generate ICNS”。这根本没有信息。
回答by qed
I have written a bash script for making icns from a svg file:
我编写了一个 bash 脚本,用于从 svg 文件制作 icns:
#!/usr/bin/env bash
sizes=(16 32 64 128 256 512)
largfile='[email protected]'
if [ ! -f "$largfile" ]; then
convert -background none -resize 1024x1024 "" "$largfile"
fi
for s in "${sizes[@]}"; do
echo $s
convert -background none -resize ${s}x${s} "$largfile" "icon_${s}x$s.png"
done
cp 'icon_32x32.png' '[email protected]'
mv 'icon_64x64.png' '[email protected]'
cp 'icon_256x256.png' '[email protected]'
cp 'icon_512x512.png' '[email protected]'
mkdir icon.iconset
mv icon_*x*.png icon.iconset
iconutil -c icns icon.iconset
Make sure you have imagemagick installed with librsvg support, on mac:
确保在 mac 上安装了支持 librsvg 的 imagemagick:
brew install imagemagick --with-librsvg
This script has served me quite well.
这个脚本对我很有帮助。
Update
更新
For a more thorough treatment, I have created a command line tool (written in Swift) for generating AppIcon.appiconset
with the correct layout and format:
为了进行更彻底的处理,我创建了一个命令行工具(用 Swift 编写),用于生成AppIcon.appiconset
正确的布局和格式:
回答by Telmo Dias
Same as @Henry (comment above) but takes as argument the PNG filename and outputs the ICNS with the same name.
与@Henry(上面的评论)相同,但将 PNG 文件名作为参数并输出具有相同名称的 ICNS。
NOTE :The PNG file name is only expected to have 1 point to separate extension, i.e. xpto.png .
注意:PNG 文件名只需要 1 个点来分隔扩展名,即 xpto.png 。
So, save the code below to a filed called "CreateICNS.src" in the folder where your png file is.
因此,将下面的代码保存到 png 文件所在文件夹中名为“CreateICNS.src”的文件中。
CODE :
代码 :
IFS='.' read -ra ADDR <<< ""
ICONSET=${ADDR[0]}.iconset
mkdir $ICONSET
sips -z 16 16 --out $ICONSET/icon_16x16.png
sips -z 32 32 --out $ICONSET/[email protected]
sips -z 32 32 --out $ICONSET/icon_32x32.png
sips -z 64 64 --out $ICONSET/[email protected]
sips -z 128 128 --out $ICONSET/icon_128x128.png
sips -z 256 256 --out $ICONSET/[email protected]
sips -z 256 256 --out $ICONSET/icon_256x256.png
sips -z 512 512 --out $ICONSET/[email protected]
sips -z 512 512 --out $ICONSET/icon_512x512.png
cp $ICONSET/[email protected]
iconutil -c icns $ICONSET
rm -R $ICONSET
HOW TO USE :
如何使用 :
Then in the terminal, "cd" to the same folder and type :
然后在终端中,“cd”到同一文件夹并键入:
source CreateICNS.src {PNG filename}
where {PNG filename} is the name of your PNG file, i.e. xpto.png .
其中 {PNG filename} 是您的 PNG 文件的名称,即 xpto.png 。
If your file would be named abc.png you would use :
如果您的文件将被命名为 abc.png,您将使用:
source CreateICNS.src abc.png
回答by eonist
Dead simple .png .icns
死简单.png .icns
- Download IconMaker.app- It's just an .applescript won't bite
- Drag and drop your .png onto the IconMaker.app you just created.
- 下载IconMaker.app- 这只是一个不会咬人的 .applescript
- 将您的 .png 拖放到您刚刚创建的 IconMaker.app 上。
More info: http://eon.codes/blog/2016/12/06/Creating-an-app-icon/
更多信息:http: //eon.codes/blog/2016/12/06/Creating-an-app-icon/
High sierra updateiconutil
is now more strict about the source .png size. More about this in the blog post after the jump. ??
高山脉更新iconutil
现在对源 .png 大小更加严格。在跳转后的博客文章中详细介绍了这一点。??
回答by dardo82
I've refactored @Henry's script to make it look better:
我重构了@Henry 的脚本以使其看起来更好:
#!/bin/zsh
NAME=$(basename .png); DIR="$NAME.iconset"
mkdir -pv $DIR
for m r in 'n' '' '((n+1))' '@2x'; do
for n in $(seq 4 9 | grep -v 6); do
p=$((2**$m)); q=$((2**$n))
OUT="$DIR/icon_${q}x${q}${r}.png"
sips -z $p $p --out $OUT
done
done
iconutil -c icns $DIR
rm -frv $DIR
Update
更新
The -c
parameter to iconutil is no longer supported. Use -—convert
instead:
-c
不再支持 iconutil的参数。使用-—convert
来代替:
#!/bin/zsh
NAME=$(basename .png); DIR="$NAME.iconset"
mkdir -pv $DIR
for m r in 'n' '' '((n+1))' '@2x'; do
for n in $(seq 4 9 | grep -v 6); do
p=$((2**$m)); q=$((2**$n))
OUT="$DIR/icon_${q}x${q}${r}.png"
sips -z $p $p --out $OUT
done
done
iconutil -—convert icns $DIR
rm -frv $DIR