Message
| Well this can be achieved fairly well. You need to muck around creating alpha masks, but that is no big deal. I have put together a demo illustrating the idea (screenshots in the next post).
You can reproduce this by simply right-clicking on the images on this page, saving them to disk, and then trying out the alias I made.
Basically I drew a 200 x 200 pixel avatar (this is probably much too big) in Photoshop, using three layers. Then each layer was saved separately to disk as the image itself, and a mask. The mask is white where you want to keep it, and black where you don't. The blur on the mask helps make a nice transition.
EDIT: Redrawn images by Isobel Gammon.
The images are (see below for what they look like):
- face.png
- coat.png
- hair.png
- face alpha.png
- coat alpha.png
- hair alpha.png
The first alias illustrates simply loading in the images in the right order, and copying them to the "test" miniwindow giving the results below (unmodified_avatar.png).
The function WindowMergeImageAlpha uses the mask image to control what parts of the image are copied.
<aliases>
<alias
match="mw"
enabled="y"
send_to="12"
sequence="100"
>
<send>
dir = GetInfo (56) .. "Avatar\\\\" -- where I put the images
win = "test"
WindowCreate (win,
0, -- left
0, -- top
200, -- width
200, -- height
6, -- mode
0, -- flags
ColourNameToRGB ("navajowhite"))
-- load images and masks
check (WindowLoadImage (win, "face", dir .. "face.png"))
check (WindowLoadImage (win, "face alpha", dir .. "face alpha.png"))
check (WindowLoadImage (win, "coat", dir .. "coat.png"))
check (WindowLoadImage (win, "coat alpha", dir .. "coat alpha.png"))
check (WindowLoadImage (win, "hair", dir .. "hair.png"))
check (WindowLoadImage (win, "hair alpha", dir .. "hair alpha.png"))
-- combine images to get avatar
WindowMergeImageAlpha (win, "coat", "coat alpha", 0, 0, 0, 0, 0, 1)
WindowMergeImageAlpha (win, "face", "face alpha", 0, 0, 0, 0, 0, 1)
WindowMergeImageAlpha (win, "hair", "hair alpha", 0, 0, 0, 0, 0, 1)
WindowShow (win, true)
</send>
</alias>
</aliases>
The alias below modifies the colours of the hair and coat using a "scratch" window (which is never seen) to blend in a fixed colour with the avatar part. This part is where you would let the player choose their colour (eg. hair colour, coat colour). With a bit of experimenting with blend modes (of which there are many) you should be able to keep the original texture of your starting image, but modify the colour.
The results are below in modified_avatar.png.
<aliases>
<alias
match="mw2"
enabled="y"
send_to="12"
sequence="100"
>
<send>
dir = GetInfo (56) .. "Avatar\\\\" -- where I put the images
win = "test"
scratch = "scratch"
WindowCreate (win,
0, -- left
0, -- top
200, -- width
200, -- height
6, -- mode
0, -- flags
ColourNameToRGB ("navajowhite"))
-- create scratch window to make colour changes
WindowCreate ("scratch", 0, 0, 200, 200, 6, 0, 0)
-- load images and masks
check (WindowLoadImage (win, "face", dir .. "face.png"))
check (WindowLoadImage (win, "face alpha", dir .. "face alpha.png"))
check (WindowLoadImage (scratch, "coat", dir .. "coat.png"))
check (WindowLoadImage (win, "coat alpha", dir .. "coat alpha.png"))
check (WindowLoadImage (scratch, "hair", dir .. "hair.png"))
check (WindowLoadImage (win, "hair alpha", dir .. "hair alpha.png"))
-- fill with desired colour
WindowRectOp ("scratch", 2, 0, 0, 0, 0, ColourNameToRGB ("red"))
-- blend into image
WindowBlendImage(scratch, "hair", 0, 0, 0, 0, 63, 1) -- colour mode
WindowImageFromWindow (win, "hair fixed", scratch) -- turn into image
-- fill with desired colour
WindowRectOp (scratch, 2, 0, 0, 0, 0, ColourNameToRGB ("darkblue"))
-- blend into image
WindowBlendImage(scratch, "coat", 0, 0, 0, 0, 63, 1) -- colour mode
WindowImageFromWindow (win, "coat fixed", scratch) -- turn into image
-- combine images to get avatar
WindowMergeImageAlpha (win, "coat fixed", "coat alpha", 0, 0, 0, 0, 0, 1)
WindowMergeImageAlpha (win, "face", "face alpha", 0, 0, 0, 0, 0, 1)
WindowMergeImageAlpha (win, "hair fixed", "hair alpha", 0, 0, 0, 0, 0, 1)
WindowShow (win, true)
</send>
</alias>
</aliases>
EDIT: 3rd June - changed images to ones drawn by my young daughter, and modified code to fix bugs in the merging of the images with the colours.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|