Replace colour in every icon resolution in an .ICO file

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?".
Post Reply
User avatar
rossmcm
Posts: 28
Joined: 2012-07-26T06:10:38-07:00
Authentication code: 15
Location: Auckland, NZ

Replace colour in every icon resolution in an .ICO file

Post by rossmcm »

I have extracted the icons for the command prompt in Windows 10 - using the freeware IcoFX:

Image

I want to create different versions of this icon set with the white pixels replaced with another colour. IcoFX has menu entries for this, but they only act on the currently selected icon size variant, and to do all sizes for a succession of colours will take a long time.

Just to recap, I have the file

Code: Select all

Windows Command Prompt Icon.ico
, and I want to produce files

Code: Select all

Windows Command Prompt Icon (red).ico
Windows Command Prompt Icon (blue).ico
Windows Command Prompt Icon (cyan).ico
...
etc.
(TIA)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replace colour in every icon resolution in an .ICO file

Post by snibgo »

If you provided a link to your icon file, we could try it out. If you told us which version of IM you used, we could give the correct command name.

But this might work:

Code: Select all

convert "Windows Command Prompt Icon.ico" -fill Red -opaque White "Windows Command Prompt Icon (red).ico"
snibgo's IM pages: im.snibgo.com
User avatar
rossmcm
Posts: 28
Joined: 2012-07-26T06:10:38-07:00
Authentication code: 15
Location: Auckland, NZ

Re: Replace colour in every icon resolution in an .ICO file

Post by rossmcm »

Thanks for answering:

https://www.dropbox.com/s/7mzzrw4rg5iwu ... n.ico?dl=0

Version: ImageMagick 6.9.0-0 Q16 x64 2014-11-14

whoops. Dropbox have gone all stupid with their file sharing: Trying this:
https://www.dropbox.com/s/7mzzrw4rg5iwu ... n.ico?dl=1 (seems to work - right-click and choose "save link as")
and...
https://www.dropbox.com/s/7mzzrw4rg5iwu ... .ico?raw=0 (wants to save it as an html file)
https://www.dropbox.com/s/7mzzrw4rg5iwu ... .ico?raw=1 (seems to work)
Last edited by rossmcm on 2017-11-13T18:06:27-07:00, edited 2 times in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replace colour in every icon resolution in an .ICO file

Post by snibgo »

Yes, that worked. Repeat for whatever colours you want.
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Replace colour in every icon resolution in an .ICO file

Post by GeeMack »

rossmcm wrote: 2017-11-13T17:04:44-07:00I want to create different versions of this icon set with the white pixels replaced with another colour. IcoFX has menu entries for this, but they only act on the currently selected icon size variant, and to do all sizes for a succession of colours will take a long time.
I get an orange version of the input icon by using IM 6.9.9-20 and this command...

Code: Select all

convert "Windows Command Prompt Icon.ico" -fill orange -tint 100 icon_orange.ico
There seems to be an issue with the transparent background when using IM 7.0.7-11.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Replace colour in every icon resolution in an .ICO file

Post by fmw42 »

@GeeMack: Why are you tinting. Tinting does something else than what the OP requested. It adds tint color to the mid grays.

But I agree that the alpha channel is turned opaque in IM 7.0.7.11. So I would say there is a bug.
User avatar
rossmcm
Posts: 28
Joined: 2012-07-26T06:10:38-07:00
Authentication code: 15
Location: Auckland, NZ

Re: Replace colour in every icon resolution in an .ICO file

Post by rossmcm »

@snibgo Many thanks. Yes, that did the trick.

However. Not really an ImageMagick question but...

The reason I wanted to do this was so that I could differentiate between several command prompt icons on my taskbar

(Image)

but changing the icon file for the taskbar has no effect on the small icon displayed. If I right-click the icon on the taskbar, I can see the different-coloured icon I have set.

Image

It's as if the icons are cached somewhere (I don't suppose you have any ideas...?)
User avatar
rossmcm
Posts: 28
Joined: 2012-07-26T06:10:38-07:00
Authentication code: 15
Location: Auckland, NZ

Re: Replace colour in every icon resolution in an .ICO file

Post by rossmcm »

Found it.

Code: Select all

C:\Users\<your username>\AppData\Local\Microsoft\Windows\Explorer
has the icon cache.

To rectify:
  • open a command prompt
  • type the following commands

Code: Select all

cd C:\Users\<your username>\AppData\Local\Microsoft\Windows\Explorer
taskkill /im explorer.exe /f
del iconcache_*.db
explorer
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replace colour in every icon resolution in an .ICO file

Post by snibgo »

rossmcm wrote:The reason I wanted to do this was so that I could differentiate between several command prompt icons on my taskbar
Not really IM, but you may find the Microsoft "title" command useful. On my Windows computer, I use:

Code: Select all

title %CD%
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Replace colour in every icon resolution in an .ICO file

Post by fmw42 »

The following command seems to work in IM 6.9.9.24 beta and IM 7.0.7.12 beta

Code: Select all

convert "Windows Command Prompt Icon.ico" -fill orange -tint 100 icon_orange.ico

Code: Select all

magick "Windows Command Prompt Icon.ico" -fill orange -tint 100 icon_orange.ico
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Replace colour in every icon resolution in an .ICO file

Post by GeeMack »

fmw42 wrote: 2017-11-13T18:34:46-07:00@GeeMack: Why are you tinting. Tinting does something else than what the OP requested. It adds tint color to the mid grays.
I read the OP too fast and got ahead of myself. I was recently working with several methods for coloring and tinting grayscale weather satellite images to get various similar results. Here's a way to change all levels of white to a color...

Code: Select all

convert "Windows Command Prompt Icon.ico" +level-colors black,orange "Windows Command Prompt Icon (orange).ico"
But I agree that the alpha channel is turned opaque in IM 7.0.7.11. So I would say there is a bug.
The command above also loses transparency with IM 7.0.7-11. It looks like that may be resolved in the next release.
User avatar
rossmcm
Posts: 28
Joined: 2012-07-26T06:10:38-07:00
Authentication code: 15
Location: Auckland, NZ

Re: Replace colour in every icon resolution in an .ICO file

Post by rossmcm »

snibgo wrote: 2017-11-14T05:29:13-07:00
rossmcm wrote:The reason I wanted to do this was so that I could differentiate between several command prompt icons on my taskbar
Not really IM, but you may find the Microsoft "title" command useful. On my Windows computer, I use:

Code: Select all

title %CD%
Thanks @snibgo, I never knew about "title". Could be useful, but of course, it is only useful if there is a command prompt window open. If there isn't, you have to hover over the icon and wait for the hint.

We've drifted off topic a bit, but do you know if there is any way of suppressing the "Administrator:" windows inserts in front of the title string? As it is, I can't see the title because the word "Administrator" fills up most of the title bar:

Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replace colour in every icon resolution in an .ICO file

Post by snibgo »

rossmcm wrote:... suppressing the "Administrator:" windows inserts in front of the title string?
You might need to hack a file. For example, see https://social.technet.microsoft.com/Fo ... tasecurity
snibgo's IM pages: im.snibgo.com
User avatar
rossmcm
Posts: 28
Joined: 2012-07-26T06:10:38-07:00
Authentication code: 15
Location: Auckland, NZ

Re: Replace colour in every icon resolution in an .ICO file

Post by rossmcm »

@snibgo, Yep, I found that. Started off on the journey, but the property sheets have changed in Windows 10 since that was written and I got a bit lost/bored/annoyed. As someone else remarked - why doesn't someone write a utility to do it?

Thanks for your help.
Post Reply