Combining Images

Is it possible to combine two or more images into a new image. My use case is a character builder where the head is separate from the clothing. I need to combine them into a new single sprite. If they are two sprites the head separates from the body when it encounters a wall. Being “attached” or following also does not work around walls.

Is it possible to replace sections of the image with the colors from another image? Perhaps it needs to be done by JavaScript.