dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.31k stars 956 forks source link

Shrink/ losslessly compress `ICO` resource files to reduce size of apps published with SingleFile/AOT #11370

Open elachlan opened 2 months ago

elachlan commented 2 months ago

In #9911 it was discovered that the embedded ICO resource files have a non-trivial size and could be losslessly compressed upwards of 90% of original file size. 329946128-158858e8-7497-4b0e-86cd-c4e49bc39de4

We should use GIMP or similar tool to shrink each of the ICO files and maybe investigate the use of PNG to reduce file sizes.

elachlan commented 2 months ago

I was able to shrink alignment.ico from 54kb to 10kb. But Image Magick required extracting them first and then recombining.

MichalStrehovsky commented 2 months ago

I was able to shrink alignment.ico from 54kb to 10kb. But Image Magick required extracting them first and then recombining.

alignment.ico can be 2.5 kB. ImageMagick will still store them as BMP for some reason (with a smaller bit depth, but still uncompressed BMP). Try this instead:

sudo apt install imagemagick --install-recommends
sudo apt install icoutils
convert alignment.ico alignment.png
icotool -c -o alignment-new.ico -r alignment-0.png -r alignment-1.png -r alignment-2.png -r alignment-3.png -r alignment-4.png -r alignment-5.png -r alignment-6.png
JeremyKuhne commented 2 months ago

If we don't lose individual icon sizes and the rendered bitmap is identical, then I'm fine with this.

elachlan commented 2 months ago

The process we used unpacks the icon into individual image files for each size contained. Then converts the images to png to compress them and repacks them into the ico. As far as I could tell they are identical on the files I checked.