favicon.png 与 favicon.ico - 为什么我应该使用 PNG 而不是 ICO?

发布于 2024-08-04 00:15:24 字数 106 浏览 7 评论 0原文

除了 PNG 是一种更常见的图像格式这一事实之外,还有其他技术原因支持 favicon.png 与 favicon.ico 吗?

我支持现代浏览器,它们都支持 PNG 最喜欢的图标。

Other than the fact that PNG is a more common image format, is there any technical reason to favor favicon.png vs. favicon.ico?

I'm supporting modern browsers which all support PNG favorite icons.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

花期渐远 2024-08-11 00:15:25

如果您想要可靠的 IE6 兼容性,请在任何情况下避免使用 PNG。

Avoid PNG in any case if you want reliable IE6 compatibility.

我的痛♀有谁懂 2024-08-11 00:15:24

所有现代浏览器(使用 Chrome 4、Firefox 3.5、IE8、Opera 10 和 Safari 4 进行测试)将始终请求 favicon.ico,除非您通过 指定了快捷方式图标。因此,如果您没有明确指定,最好始终有一个 favicon.ico 文件,以避免 404。雅虎!建议您将其缩小并可缓存。

而且您也不必仅仅为了 alpha 透明度而选择 PNG。 ICO 文件 支持 alpha 透明度很好(即 ​​32 位颜色),尽管几乎没有工具允许您创建它们。我经常使用 Dynamic Drive 的 FavIcon Generator 创建带有 alpha 的 favicon.ico 文件透明度。这是我所知道的唯一可以做到这一点的在线工具。

还有一个免费的 Photoshop 插件可以创建它们。

All modern browsers (tested with Chrome 4, Firefox 3.5, IE8, Opera 10 and Safari 4) will always request a favicon.ico unless you've specified a shortcut icon via <link>. So if you don't explicitly specify one, it's best to always have a favicon.ico file, to avoid a 404. Yahoo! suggests you make it small and cacheable.

And you don't have to go for a PNG just for the alpha transparency either. ICO files support alpha transparency just fine (i.e. 32-bit color), though hardly any tools allow you to create them. I regularly use Dynamic Drive's FavIcon Generator to create favicon.ico files with alpha transparency. It's the only online tool I know of that can do it.

There's also a free Photoshop plug-in that can create them.

新一帅帅 2024-08-11 00:15:24

由于该线程中其他人的大量更新和注释,答案被替换(并变成了社区 Wiki):

  • ICO 和 PNG 都允许基于完全 alpha 通道的透明度
  • ICO 允许向后兼容旧浏览器(例如 IE6)
  • PNG 可能具有更广泛的工具支持透明度,但您也可以找到创建 alpha 通道 ICO 的工具,例如动态驱动工具以及 @mercator 提到的 Photoshop 插件

请随时查阅此处的其他答案以了解更多详细信息。

Answer replaced (and turned Community Wiki) due to numerous updates and notes from various others in this thread:

  • ICOs and PNGs both allow full alpha channel based transparency
  • ICO allows for backwards compatibility to older browsers (e.g. IE6)
  • PNG probably has broader tooling support for transparency, but you can find tools to create alpha-channel ICOs as well, such as the Dynamic Drive tool and Photoshop plugin mentioned by @mercator.

Feel free to consult the other answers here for more details.

野却迷人 2024-08-11 00:15:24

.png 文件很好,但 .ico 文件也提供 alpha 通道透明度,加上它们为您提供向后兼容性。

例如,看看 StackOverflow 使用的类型(请注意,它是透明的):

<link rel="shortcut icon" href="https://cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico"> 
<link rel="apple-touch-icon" href="https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png">

apple-itouch 是为 iphone 用户创建网站快捷方式的。

.png files are nice, but .ico files provide alpha-channel transparency, too, plus they give you backwards compatibility.

Have a look at which type StackOverflow uses for example (note that it's transparent):

<link rel="shortcut icon" href="https://cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico"> 
<link rel="apple-touch-icon" href="https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png">

The apple-itouch thingy is for iphone users that make a shortcut to a website.

甜宝宝 2024-08-11 00:15:24

*.ico 文件的理论上的优点是它们是可以容纳多个图标的容器。例如,您可以为旧系统存储带有 Alpha 通道和 16 色版本的图像,或者您可以添加 32x32 和 48x48 图标(例如,将链接拖动到 Windows 资源管理器时会显示)。

然而,这个好主意往往会与浏览器的实现发生冲突。

The theoretical advantage of *.ico files is that they are containers than can hold more than one icon. You could for instance store an image with alpha channel and a 16 colour version for legacy systems, or you could add 32x32 and 48x48 icons (which would show up when e.g. dragging a link to Windows explorer).

This good idea, however, tends to clash with browser implementations.

找个人就嫁了吧 2024-08-11 00:15:24

PNG 有两个优点:尺寸更小,使用和支持更广泛(除了案例图标)。
正如之前提到的 ICO,可以有多种尺寸的图标,这对于桌面应用程序很有用,但对于网站来说就不太方便了。
我建议您将 favicon.ico 放在应用程序的根目录中。如果您有权访问网站页面的标题,请使用标签指向 png 文件。
因此,较旧的浏览器将显示 favicon.ico,而较新的浏览器将显示 png。

要创建 Png 和 Icon 文件,我推荐 The Gimp

PNG has 2 advantages: it has smaller size and it's more widely used and supported (except in case favicons).
As mentioned before ICO, can have multiple size icons, which is useful for desktop applications, but not too much for websites.
I would recommend you to put a favicon.ico in the root of your application. An if you have access to the Head of your website pages use the tag to point to a png file.
So older browser will show the favicon.ico and newer ones the png.

To create Png and Icon files I would recommend The Gimp.

烛影斜 2024-08-11 00:15:24

一些社交工具(例如 Google+)使用一种简单的方法来获取外部链接的图标,即获取
http://your.domainname.com/favicon.ico

因为它们不会预取 HTML内容, 标记将不起作用。在这种情况下,您可能需要使用 mod_rewrite 规则或仅将文件放置在默认位置。

Some social tools like Google+ use a simple method to get a favicon for external links, fetching
http://your.domainname.com/favicon.ico

Since they don't prefetch the HTML content, the <link> tag will not work. In this case, you might want to use a mod_rewrite rule or just place the file in the default location.

爱你不解释 2024-08-11 00:15:24

ico 可以为 png。

更准确地说,您可以在这种最小容器格式中存储一个或多个 png,而不是每个人都与 ico 强烈关联的通常位图+alpha。

支持是旧的,出现在 Windows Vista (2007) 和浏览器很好地支持,但图标编辑软件不一定支持。

任何有效的 png(包括标头)都可以在前面加上 6 字节 ico 标头 和 16 字节图像目录。
GIMP 有本机支持。只需导出为 ico 并勾选“压缩 (PNG)”即可。

An ico can be a png.

More precisely, you can store one or more png inside this minimal container format, instead of the usual bitmap+alpha that everyone strongly associates with ico.

Support is old, appearing in Windows Vista (2007) and is well supported by browsers, though not necessarily by icon editing software.

Any valid png (whole including header) can be prepended by a 6 byte ico header and 16 byte image directory.
GIMP has native support. Simply export as ico and tick "Compressed (PNG)".

从﹋此江山别 2024-08-11 00:15:24

为了它的价值,我这样做:

    <!-- Favicon - Generic -->
    <link rel="icon" href="path/favicon-32_x_32.png" sizes="32x32">
    <link rel="icon" href="path/favicon-57_x_57.png" sizes="57x57">
    <link rel="icon" href="path/favicon-76_x_76.png" sizes="76x76">
    <link rel="icon" href="path/favicon-96_x_96.png" sizes="96x96">
    <link rel="icon" href="path/favicon-128_x_128.png" sizes="128x128">
    <link rel="icon" href="path/favicon-192_x_192.png" sizes="192x192">
    <link rel="icon" href="path/favicon-228_x_228.png" sizes="228x228">
    <!-- Favicon - Android -->
    <link rel="shortcut icon" href="path/favicon-196_x_196.png" sizes="196x196">
    <!-- Favicon - iOS -->
    <link rel="apple-touch-icon" href="path/favicon-120_x_120.png" sizes="120x120">
    <link rel="apple-touch-icon" href="path/favicon-152_x_152.png" sizes="152x152">
    <link rel="apple-touch-icon" href="path/favicon-180_x_180.png" sizes="180x180">

并且我仍然将favicon.ico保留在根目录中。有上百万种工具可以将 PNG 转换为 ICO。我使用 PNG2ICO

我使用的其他工具是 Derivv。对于输入,我使用任何至少 228px * 228px 大的方形图像,并且我想将其用于图标。我将其命名为“favicon.png”,因此输出的名称始终如上面的 HTML 代码片段所示。为了避免手动输入所有尺寸,我导出了一次 CSV,然后每次都重复使用同一个。其内容为:

width,height
32,32
57,57
76,76
96,96
128,128
192,192
228,228
196,196
120,120
152,152
180,180
,

For what it's worth, I do this:

    <!-- Favicon - Generic -->
    <link rel="icon" href="path/favicon-32_x_32.png" sizes="32x32">
    <link rel="icon" href="path/favicon-57_x_57.png" sizes="57x57">
    <link rel="icon" href="path/favicon-76_x_76.png" sizes="76x76">
    <link rel="icon" href="path/favicon-96_x_96.png" sizes="96x96">
    <link rel="icon" href="path/favicon-128_x_128.png" sizes="128x128">
    <link rel="icon" href="path/favicon-192_x_192.png" sizes="192x192">
    <link rel="icon" href="path/favicon-228_x_228.png" sizes="228x228">
    <!-- Favicon - Android -->
    <link rel="shortcut icon" href="path/favicon-196_x_196.png" sizes="196x196">
    <!-- Favicon - iOS -->
    <link rel="apple-touch-icon" href="path/favicon-120_x_120.png" sizes="120x120">
    <link rel="apple-touch-icon" href="path/favicon-152_x_152.png" sizes="152x152">
    <link rel="apple-touch-icon" href="path/favicon-180_x_180.png" sizes="180x180">

And I still keep the favicon.ico in root. There's a million tools for converting PNG to ICO out there. I use PNG2ICO.

Additional tool I use is Derivv. For input I use any square image that is at least 228px * 228px big, and I want to use for the favicon. I name it "favicon.png", so the output is always named as in the HTML snippet above. To avoid typing all of the sizes manually I exported the CSV once, and then I reuse the same one every time. It's contents:

width,height
32,32
57,57
76,76
96,96
128,128
192,192
228,228
196,196
120,120
152,152
180,180
,
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文