
我有一個灰階 PNG,當嘗試使用 ImageMagick(版本 7.1.1-28)創建 ICO 文件它總是給我以下警告:
$ convert favicon.png -define icon:auto-resize=16,32,48,64,256 favicon.ico
convert: Cannot write image with defined png:bit-depth or png:color-type. `' @ warning/png.c/MagickPNGWarningHandler/1526.
我認為這可能是我原始PNG 的顏色配置文件,所以我嘗試使用ImageMagick 將圖像(也許我的假設在這裡不正確?)首先強制為RGB 顏色空間,然後從該中間文件製作ICO 文件,但得到了確切的結果同樣的錯誤。
$ convert favicon.png +profile "*" -colorspace RGB ico-temp.png
$ convert ico-temp.png -define icon:auto-resize=16,32,48,64,256 favicon.ico
convert: Cannot write image with defined png:bit-depth or png:color-type. `' @ warning/png.c/MagickPNGWarningHandler/1526.
我在這裡做錯了什麼?我可以添加任何標誌來完成這項工作嗎?
對於任何想要嘗試複製的人,我發現任何灰階 SVG 或 PNG 轉換為 ICO 檔案都會出現此錯誤。這是我為重現此內容而製作的 SVG 範例(如果您使用此來源將其轉換為 PNG,也可以使用):
<svg xmlns="http://www.w3.org/2000/svg"
width="100mm"
height="100mm"
viewBox="0 0 100 100">
<circle cx="25" cy="75" r="20" style="fill:#ccc"/>
<circle cx="65" cy="35" r="30" style="fill:#4d4d4d"/>
</svg>
答案1
它認為解決方案-compress none
用作在這裡解釋;在 macOS 上安裝的 ImageMagick 7.1.1-28 中進行了測試:
convert favicon.png -compress none -define icon:auto-resize=16,32,48,64,256 favicon.ico
當我將你的範例favicon.svg
轉換為時favicon.png
,它乾淨地創建了一個favicon.ico
沒有問題的。
其他嘗試如下。
如建議的那樣呢這個答案:
convert -background transparent "favicon.png" -define icon:auto-resize=16,24,32,48,64,72,96,128,256 "favicon.ico"
或者也許建議-define profile:skip=ICC
用作在這裡建議和-background transparent
:
convert -background transparent "favicon.png" -define profile:skip=ICC -define icon:auto-resize=16,24,32,48,64,72,96,128,256 "favicon.ico"
或者沒有-background transparent
:
convert "favicon.png" -define profile:skip=ICC -define icon:auto-resize=16,24,32,48,64,72,96,128,256 "favicon.ico"