FavIcon generation

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Locked
Hunter23071985
Posts: 30
Joined: 2019-01-03T12:48:14-07:00
Authentication code: 1152

FavIcon generation

Post by Hunter23071985 »

Hi!
Please help me refine "_ StartMe.cmd" that extracts icon from executable file and assigns it to another executable file.

Code: Select all

rem any2ico.exe, https://www.carifred.com/quick_any2ico/
rem magick.exe (ImageMagick-7.0.9-16-portable-Q16-x86.zip), https://imagemagick.org/script/download.php#windows
rem pngquant.exe, https://pngquant.org/pngquant-windows.zip
rem fasm.exe, http://flatassembler.net/download.php
rem dummy.exe, https://github.com/vweevers/win-dummy-exe/releases
rem rcedit.exe, https://github.com/electron/rcedit/releases
rem rexplorer.exe, https://www.sordum.org/9192/restart-explorer-v1-4/

REM SAVING ICO FROM EXE
cd /d tools
any2ico.exe "-res=..\XXX.exe" "-icon=XXX.ico"

REM EXTRACTING THE BEST PNG FROM ICO
magick.exe XXX.ico ^
  ( -clone 0--1 -layers Merge ) ^
  -channel A -evaluate Multiply %%[fx:w==u[-1].w?1:0]% +channel ^
  +delete -background none -layers merge XXX.png

REM BUILDING PNG FILES WITH 256X256, 128X128, 64X64, 32X32 PIXELS RESOLUTION
rem (closest to the 310x310, 150x150, 70x70, 32x32 icons used in Windows, http://net-informations.com/faq/asp/favicon.htm)
magick.exe XXX.png -resize 256x256 256.png && pngquant.exe --skip-if-larger --speed 1 --strip --quality=65-80 --ext=.png --force 256.png
magick.exe XXX.png -resize 128x128 128.png && pngquant.exe --skip-if-larger --speed 1 --strip --quality=65-80 --ext=.png --force 128.png
magick.exe XXX.png -resize 64x64   064.png && pngquant.exe --skip-if-larger --speed 1 --strip --quality=65-80 --ext=.png --force 064.png
magick.exe XXX.png -resize 32x32   032.png && pngquant.exe --skip-if-larger --speed 1 --strip --quality=65-80 --ext=.png --force 032.png

REM BUILDING ICO WITH FASM (SIZE DESCENDING - http://www.py2exe.org/index.cgi/CustomIcons)
rem (magick.exe overblow size, winterdrache png2ico.exe gives artifacts, Niall's png2ico has no cmd-interface)
fasm.exe fasm.asm ..\XXX.ico

REM EMBEDDING ICO AND APP-INFO FOR THE DUMMY APP
copy /y dummy.exe ..\ZZZ.exe
rcedit.exe ..\ZZZ.exe --set-icon ..\XXX.ico
for %%i in (CompanyName, LegalCopyright, ProductName, FileVersion, ProductVersion, FileDescription, OriginalFilename) do (
  for /f "delims=" %%j in ('rcedit.exe ..\XXX.exe --get-version-string "%%~i"') do (
    if "%%i"=="FileVersion" (
       rcedit.exe ..\ZZZ.exe --set-file-version %%~j
    ) else (
      if "%%i"=="ProductVersion" (
       rcedit.exe ..\ZZZ.exe --set-product-version %%~j
      ) else (
       rcedit.exe ..\ZZZ.exe --set-version-string "%%~i" "%%~j"
      )
    )
  )
)

REM RESTORING PNG-ICON IN EXPLORER, REMOVE ICON CACHE AND GARBAGE
del *.png && del *.ico
ie4uinit.exe -cleariconcache
ie4uinit.exe -show
rexplorer.exe
Test Sample: Download / Delete
Hope for your help. Thanks!
Last edited by Hunter23071985 on 2020-01-14T14:33:09-07:00, edited 3 times in total.

Hunter23071985
Posts: 30
Joined: 2019-01-03T12:48:14-07:00
Authentication code: 1152

Re: FavIcon generation

Post by Hunter23071985 »

del
Last edited by Hunter23071985 on 2020-01-14T14:33:28-07:00, edited 1 time in total.

Hunter23071985
Posts: 30
Joined: 2019-01-03T12:48:14-07:00
Authentication code: 1152

Re: FavIcon generation

Post by Hunter23071985 »

del
Last edited by Hunter23071985 on 2020-01-14T14:27:35-07:00, edited 1 time in total.

User avatar
GeeMack
Posts: 757
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: FavIcon generation

Post by GeeMack »

Hunter23071985 wrote:
2020-01-12T13:00:27-07:00
How to compress all icons inside the .ICO file?
With ImageMagick you can easily convert a single square image to an icon containing several sizes. At it's simplest this IMv6 command should create an example...

Code: Select all

convert logo: -shave 80x0 -define icon:auto-resize="256,128,64,32,16" imicon.ico
Use any image instead of "logo:" and shave or crop it square.

For IMv7 use "magick" instead of "convert".

If you need to include multiple sizes of one image and a single size of another, it can be done with IM, but it's a bit more complicated.

I don't know much about optimizing.

Hunter23071985
Posts: 30
Joined: 2019-01-03T12:48:14-07:00
Authentication code: 1152

Re: FavIcon generation

Post by Hunter23071985 »

GeeMack, your code is the same as mine from post #2 and gives the same 139.0 KB instead of the target 28.1 KB.

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: FavIcon generation

Post by fmw42 »

If you want smaller file size, use the same colormap by using -remap on each resolution.

Hunter23071985
Posts: 30
Joined: 2019-01-03T12:48:14-07:00
Authentication code: 1152

Re: FavIcon generation

Post by Hunter23071985 »

fmw42, how to use -remap on each resolution?
Last edited by Hunter23071985 on 2020-01-14T14:28:11-07:00, edited 1 time in total.

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: FavIcon generation

Post by fmw42 »

I know little about ico files.

My concept (untested) would be to first resize the images into each resolution. Get the colormap from the largest? image -- i.e. the -unique-colors. (Possibly reduce the number of colors using -colors. That will make the files smaller, esp if saved as gif). Build an image from the unique colors. Use -dither none -remap with that colormap on each resolution level. Combine the resolutions into your ico file.

See

https://imagemagick.org/Usage/quantize/#extract
https://imagemagick.org/Usage/quantize/#remap

However, pngquant will likely do a better job as it optimized better than imagemagick.

Hunter23071985
Posts: 30
Joined: 2019-01-03T12:48:14-07:00
Authentication code: 1152

Re: FavIcon generation

Post by Hunter23071985 »

fmw42 wrote:
2020-01-13T11:33:58-07:00
However, pngquant will likely do a better job as it optimized better than imagemagick.
OK, thank you!
The first post has been updated. The code works fine, with high-quality icons there are no problems.

What is the best way to enlarge to 256x256 an icon that initially has low resolution and poor quality?
Example from here: Download / Delete.

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: FavIcon generation

Post by fmw42 »

Best way is to get the larger orginal. There is no good way to enlarge a low quality raster image to higher quality. You can try some of the -resize defines at https://imagemagick.org/Usage/filter/ni ... upsampling

Hunter23071985
Posts: 30
Joined: 2019-01-03T12:48:14-07:00
Authentication code: 1152

Re: FavIcon generation

Post by Hunter23071985 »

fmw42, thank you... Now I could not get a good result, but it's definitely possible.
The first service I found was imageupscaler.com: it does a good job in auto mode and I'm sure it could be better, than that:

Image

Here is a PNG I worked with: download / delete.
Maybe you can get something better with ImageMagick or build esrgan/srgan/superresolution for Windows?

Upd: another interesting algorithm and its implementation on CPU and on GPU.
Can anyone run this and publish the result of processing my PNG?

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: FavIcon generation

Post by fmw42 »

If you want pixel art resizing in ImageMagick see -magnify at https://imagemagick.org/script/command- ... hp#magnify

Hunter23071985
Posts: 30
Joined: 2019-01-03T12:48:14-07:00
Authentication code: 1152

Re: FavIcon generation

Post by Hunter23071985 »

fmw42, If I applied magnify correctly, it seems there are nothing to talk about. )

Code: Select all

magick.exe Source.png -define "magnify:method=eagle2X" -magnify Source-eagle2X.png
magick.exe Source.png -define "magnify:method=eagle3X" -magnify Source-eagle3X.png
magick.exe Source.png -define "magnify:method=eagle3XB" -magnify Source-eagle3XB.png
magick.exe Source.png -define "magnify:method=epb2X" -magnify Source-epb2X.png
magick.exe Source.png -define "magnify:method=EPBX2x" -magnify Source-EPBX2x.png
magick.exe Source.png -define "magnify:method=fish" -magnify Source-fish.png
magick.exe Source.png -define "magnify:method=fish2X" -magnify Source-fish2X.png
magick.exe Source.png -define "magnify:method=hq2X" -magnify Source-hq2X.png
magick.exe Source.png -define "magnify:method=scale2X" -magnify Source-scale2X.png
magick.exe Source.png -define "magnify:method=scale3X" -magnify Source-scale3X.png
magick.exe Source.png -define "magnify:method=xbr2X" -magnify Source-xbr2X.png
Image

If nothing more can be done, perhaps it's real better to find out a better ICO.
Thanks for the help!

Locked