icopng

Crates.ioicopng
lib.rsicopng
version1.0.1
sourcesrc
created_at2023-04-26 20:45:47.890689
updated_at2023-04-26 20:45:47.890689
descriptionEmbed a PNG directly into an ICO file
homepagehttps://github.com/cdown/icopng
repository
max_upload_size
id849804
size11,122
Chris Down (cdown)

documentation

README

icopng | Tests

icopng stores a PNG inside an ico, without converting to the traditional bitmap with alpha channel. This saves a lot of space, since PNGs can be compressed and there are tools to highly optimise them. Embedding PNG data inside a favicon.ico file is well supported by browsers, as well.

Compared to using GIMP, ImageMagick, or ICOEncoder, the resulting file can be an order of magnitude smaller with an optimised input PNG due to avoiding re-encoding. For example, with this input image, icopng's output is ~30% smaller than GIMP's re-encoded PNG, and ~900% smaller than traditional bitmap with alpha channel:

Engine Embedded format Size
icopng PNG 1.2KiB
GIMP PNG 1.7KiB
ImageMagick/GIMP BMP 17KiB

Usage

Here's an example of converting a traditional bitmap ico file to a PNG, and then into a PNG embedded into an ico file with this tool.

# `convert' is from ImageMagick
convert favicon-old.ico favicon.png

# Optional: Shrink the png further
pngquant --skip-if-larger --strip -f --ext .png favicon.png
optipng favicon.png

# Embed into new favicon.ico
icopng favicon.png favicon.ico

Why not just use...?

image::ico::ICOEncoder, or the ico crate

The image and ico crates do export PNGs inside ICO files (nice!), but they will re-encode them, thus losing all the benefits of things like optipng/pngquant.

ImageMagick

Tools like imagemagick can convert from PNG to ico, but they convert to bitmap with alpha instead of just putting the PNG into an ico container, which means the files are very large.

GIMP

GIMP can also export as a PNG inside an ICO by exporting as ICO and selecting "Compressed (PNG)", however then you don't get the benefits of pngquant/optipng.

Commit count: 0

cargo fmt