So instead of the name, you can get the image itself:
xprop -id THE_WINDOW_ID -notype 32c _NET_WM_ICON | perl -0777 -pe '@_=/\d+/g; printf "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE RGB_ALPHA\nENDHDR\n", splice@_,0,2; $_=pack "N*", @_; s/(.)(...)/$2$1/gs' > icon.pam
You can pipe that ouput to pamrgbatopng
(from netpbm
) to get a PNG image:
xprop -id THE_WINDOW_ID ... | perl -0777 ... | pamrgbatopng > the_icon.png
It's hacky, kinda slow, but it's something.
Credits: This is a combination of @Thomas Dickey's answer with [How to dump the icon of a running X program?](https://unix.stackexchange.com/questions/48860/how-to-dump-the-icon-of-a-running-x-program.