如何拥有多种图标大小,但默认情况下仅提供 16x16?
一般来说,以多种尺寸提供 favicon.ico 被认为是一种很好的做法,因为这样在创建快捷方式或固定站点 (IE9) 时看起来会更好。不过,这样做会使网站图标的大小轻松增加十倍,从而导致网站加载速度变慢(在我的例子中,16x16 网站图标为 1kb,16、32、64=30kb)。
Facebook 和 Yahoo 等网站默认提供小于 1kb 的 16x16 图标,但当您固定这些网站时,使用的图像大小合适。我假设只有在需要时才加载较大的图片,这解决了这个困境。我一直试图弄清楚这些网站是如何做到这一点的,但没有成功。有人知道这个吗?
Generally it is considered good practice to serve favicon.ico in multiple sizes, because that way it looks better when a shortcut is made or the site is pinned (IE9). The size of a favicon easily increases tenfold by doing so though, which results in slower site loading (in my case the 16x16 favicon is 1kb, the 16, 32, 64=30kb).
Sites like Facebook and Yahoo serve a 16x16 favicon by default that is <1kb, but when you pin these sites, the image used is proper size. I assume the larger picture is loaded only when needed, which fixes the dilemma. I have unsuccessfully been trying to figure out how these sites do this. Does anybody know this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
更新:
我的原始答案如下,但是,自从写这篇文章以来,我相信可能有更好的方法来使用 HTML 5 处理 Favicons。我会为 Internet Explorer 创建一个 32x32 favicon(仅限该尺寸) 9 及以下版本,但使用其他方法为其他浏览器(包括移动设备)创建更高分辨率的图标(PNG 文件类型)。您可以在此处查看我的答案以获取更多信息。
问题的原始答案:
具体操作方法如下:
下载 png2ico。解压到 c:\
在您最喜欢的程序中创建您的图标。创建 64x64、32x32、16x16。 (注意:可能不需要 64x64,并且会增加文件大小。但是,至少使用 32x32 和 16x16)另存为 icon-64.png(对于 64x64 大小) icon-32.png (32x32) 和 icon-16.png ( 16x16) 与 png2ico 位于同一文件夹中。将颜色保持在最低限度。
打开命令提示符 - 将目录更改为 png2ico 文件夹。 (
cd \png2ico
)进入正确的目录后,运行以下命令:
注意:由于添加了 64x64 大小的图标,文件大小的差异使文件增加了 2kb。我只会使用 32x32 和 16x16。 (运行与上面相同的代码,删除
icon-64.png
)从 png2ico 文件夹中获取 favicon.ico 文件。将其上传到服务器,在标题中添加
即可。
当您这样做时,请继续为 iPad 和 iPhone 创建图标。 您可以在此处找到有关推荐尺寸以及如何将其实施到您的网站中的更多信息。
此外,还可以在此处找到有关网站图标的更多一般信息。
注意:我不知道 Facebook 或雅虎是否这样做,但这回答了您关于如何做到这一点的问题。
Update:
My original answer is below, however, since writing this post I believe there may be a better way to handle Favicons with HTML 5. I would create a 32x32 favicon (only that size) for Internet Explorer 9 and below but use other methods for creating higher resolution favicons (PNG file type) for other browsers including mobile devices. You can see my answer here for additional information.
Original Answer to Question:
Here is how it can be done:
Download png2ico. Extract to c:\
Create your Icons in your favorite program. Create a 64x64, 32x32, 16x16. (Note: 64x64 is probably not needed and will increase file size. However, use at least 32x32 and 16x16) Save as icon-64.png (for 64x64 size) icon-32.png (32x32) and icon-16.png (16x16) in the same folder as png2ico. Keep the colors to a minimum.
Open Command Prompt - Change directories to the png2ico folder. (
cd \png2ico
)Once in the right directory run this command:
Note: The difference in file size for the addition of a 64x64 size icon increased the file by 2kb. I would just use 32x32 and 16x16. (Run same code as above removing
icon-64.png
)Grab the favicon.ico file from the png2ico folder. Upload it to the server add
<link rel="shortcut icon" href="http://example.com/favicon.ico" />
to the header and you are good to go.While you are at it go ahead and create Icons for iPad and iPhone. You can find more info on recommended sizes here and how to implement them into your site.
Also more general info on Favicons can be found here.
Note: I do not know if this is how Facebook or Yahoo do theirs but this answers your question of how it can be done.
Facebook“favicon.ico”包含两种尺寸:16x16 和 32x32。我确信您知道如何将两个 ico 图像合并为一个,但是,“技巧”是他们使用两个极其优化的图像。
我发现 Photoshop 会创建臃肿的 PNG 文件和臃肿的 ICO 文件。 (注意:Photoshop 需要一个插件来创建 ICO 文件。)
我发现创建小型、优化的 ICO 文件的最佳方法是使用名为“Gimp”的著名免费图像编辑器。简而言之,只需按照本教程创建 ICO 文件即可:
https://www.catalyst.net。 nz/news/creating-multi-resolution-favicon-include-transparency-gimp
重要提示:当您到达保存 .ico 图像的步骤时,您可以指定每像素位数 (bpp),将其更改为 4bpp 或类似的值(您必须进行试验,看看可以降到多低)且不会降低图像质量)。
使用上面的说明,我能够创建一个包含 16x16 和 32x32 图像的 1kb 图标。相比之下,我使用 Photoshop、插件和各种其他工具可以获得相同的图标的最小大小是 5kb。
The Facebook "favicon.ico" contains two sizes: 16x16 and 32x32. I'm sure you know how to combine two ico images into one, however, the "trick" is they're using two extremely optimized images.
I've found that Photoshop creates bloated PNG files, and bloated ICO files. (Note: Photoshop requires a plugin to create ICO files.)
The best way I've found to create tiny, optimized ICO files is to use a well-known free image editor called "Gimp". In short, just follow this tutorial for creating ICO files:
https://www.catalyst.net.nz/news/creating-multi-resolution-favicon-including-transparency-gimp
Important Tip: When you get to the step for saving your .ico image and you can specify the bits-per-pixel (bpp), change it to 4bpp or something similiar (you'll have to experiment to see how low you can go without degrading the image quality).
Using the instructions above, I was able to create a 1kb favicon that contains 16x16 and 32x32 images. In comparison, the smallest I could get the same favicon using Photoshop, plugins, and various other tools was 5kb.
或者您可以登录任何安装了 ImageMagick 的 Linux 机器,将源图像(分辨率至少为 256x256 像素和 PNG 格式文件)重命名为“favicon.png”,然后运行以下命令
:将您的 favicon.ico 与最知名的格式直接烘焙到一个文件中。
另外,请务必查看 favicon 备忘单 @ https://github.com/audreyr/favicon-备忘单 了解更多网站图标信息。
Or you could just log into any linux box with ImageMagick installed, rename your source image (with a resolution of at least 256x256 pixels and a PNG format file) to 'favicon.png', and run the following command:
And you'll have your favicon.ico with most well-known formats baked right into one file.
Also, be sure to checkout the favicon cheat sheet @ https://github.com/audreyr/favicon-cheat-sheet for more favicon information.
如果您喜欢脚本,我编写了一个脚本,可以使用 ImageMagick 将任何图像转换为多分辨率图标。
http://blog.lavoie.sl/2012/11 /multi-resolution-favicon-using-imagemagick.html
对于您关于为什么 Facebook 和 Yahoo 能够拥有高分辨率“固定”图像的问题,这是因为他们也有 apple-touch-icon 和 og:image。
If you like scripts, I wrote one to convert any image to a multi-resolution favicon using ImageMagick.
http://blog.lavoie.sl/2012/11/multi-resolution-favicon-using-imagemagick.html
For your question about why Facebook and Yahoo are able to have high-res "pinned" images, it is because they also have apple-touch-icon and og:image.
Windows 批处理文件,它创建多个大小的 .PNG 并将它们合并到一个 .ICO 文件:
如果您不需要 .PNG 文件,您可以通过
del FILE
删除(或删除)它们,或者您将所有 PNG 保存在您可以删除的目录中(在%imageMagick% %exportFileNames%"%~dp0%fileName%.ico"
之后)。希望它对某人有帮助。 :)
Windows batch file, which creates multiple sized .PNGs and merge them to one .ICO file:
If you don't need the .PNG files, you can delete (or remove) them by
del FILE
or you save all PNGs inside a directory you can remove (after%imageMagick% %exportFileNames%"%~dp0%fileName%.ico"
).Hope it helps somebody. :)