Because of my 'problem' I managed to inspire the creators of ImageMagick to add support for the 'hex' property for this output...
To do what I've done in the answer above now takes only the following:
magick *.png -depth 8 -set filename:f "%[hex:u.p{0,0}]" %[filename:f].png
So (for example) the image files will go from "generic-filename.png" to "#EA4858.png"
This leaves me with only a couple of issues now:
This operation makes a copy of the image (which I don't want)
The inclusion of the "#" symbol in the filename (also unwanted)
So here is my new solution based on the latest stable version of ImageMagick... which is 7.0.5-10 as of this writing), all accomplished from the Command Prompt on Windows (assuming you have ImageMagick installed).
First I want to rename all files, to give them a common prefix which I can reference later... This is the native Windows rename command:
REN "*.png" "temp_*.png"
That takes us from "generic-filename.png" to "temp_generic-filename.png"
I am starting out with images that are over 500px square. This is way bigger than I need them to be... The next line crops them down to a more manageable size using ImageMagick:
magick mogrify -gravity Center -crop 88x88+0+0 +repage *.png
The next step likewise utilizes ImageMagick to sample the color (at the top-left corner in this case) and outputs that information to the filename of the copy it makes in hex format:
magick *.png -depth 8 -set filename:f "%[hex:u.p{0,0}]" %[filename:f].png
Now we've gone from "temp_generic-filename.png" to (for example) "#EA4858.png"
Now I need to delete the original images since the copies have received the hex filenames. Again using Windows to delete all PNG images with the "temp_" prefix:
DEL "temp_*.png"
Last step I'm going to do is to remove the "#" symbol from my new filenames using 'rename' again:
REN "*.png" "/*.png"
The "/" in the last bit removes the first character. To remove 2 or more characters (from the beginning only) just add two or more forward-slashes.
All together now, and run from a Command Prompt within the image folder:
@ECHO OFF
FOR %a in (*.png) DO (
REN "*.png" "temp_*.png"
magick mogrify -gravity Center -crop 88x88+0+0 +repage *.png
magick *.png -depth 8 -set filename:f "%[hex:u.p{0,0}]" %[filename:f].png
DEL "temp_*.png"
REN "*.png" "/*.png"
)
Final files are now 88x88 and named according to their hex color code as follows: "EA4858.png"
(NOTE: It's a possibility (it's been suggested) that the next version of ImageMagic may leave out the "#" symbol in this output, which could then easily be manually added if so desired. If this happens then the last step will obviously be rendered unnecessary.)
Something I neglected to say in my original answer: Massive hat-tip to the crew over at ImageMagick for being so helpful!