I would like Photoshop to automatically execute the following task
i am familiar with python, but javascript is ok if it could do
If you want to do this on Photoshop, you need to record an action and apply it to any photo.
If you want to do this on Python, I do not know what API you want to use but the general process is to create a mask based on the position and size information from the icon image and, with bitwise operations, to merge it to the other layers. Then save it as a bmp file.
Here an example Bitwise Operations in OpenCV