views:

19

answers:

1

In a project I'll be working on soon there will be a need to generate avatars. The generation process will be one of those where the user can select different heads, hairstyles, clothing, etc. Some items will also be unavailable at first and will have to be earned or purchased.

I already have a fair idea on how to do this, but since it is a nontrivial amount of code, it would be nice to see working examples of code. Ideally I could just take a script and integrate into my page, but just gathering ideas from other people would be good too.

I'll be working with PHP, but examples in other languages are welcome too.

Added: To clarify, I don't mean a random avatar generator (or one that generates an avatar based on some hash value). A random avatar generator is subtly different from what I have intented. In a random avatar generator the programmer-artist has a much greater say of what goes where. He can carefully pick out pieces that will not conflict with each other, and he can discard those that give him trouble.

In my case the avatar generator is more like this. The user chooses which head to use, which hairstyle to apply, which piece of clothing to use, etc. There are way more pieces there, with artists adding new ones every once in a while. It's much harder to test how pieces will or won't fit together. Sometimes more advanced blending is required (like a hat would have a part of it in front of hair, and part of it behind the hair). Etc.

A: 

[EDIT: Revised answer to updated question]

I think that it's primarily a matter of designing the parts accordingly. You have some basic forms (male, female, tall / small, etc.) for which you have stylesets (e.g. hair) designed to match and align perfectly. Solving this algorithmically instead is probably a bad choice in terms of workload and probably not necessary for non-animated figures.

However, maybe you'll need some additional alpha-channel/transparency masks or something for combining head, hair and hat.

Other than that, these parts would have to be combined layer for layer like Monster ID.

Archimedix
That's different. The avatar generated there does not have real-world constraints. It doesn't have to make sense. And the script authors has quite a serious say on what images they use. However when you want to use real clothing and stuff, things get more difficult. For instance, hair might need to "fold around" the head, etc.
Vilx-
Hm, it very well depends on how your characters are designed. I guess it would be easier if they had about the same proportions so that you can easily exchange hair styles etc., sort of like the avatar generator for the Simpsons Movie website (http://www.simpsonsmovie.com/). In this case, the script would still just have to draw the layers on one another.
Archimedix
Well, naturally they will have to have the same proportions, but that isn't a panacea. For example, the hat/hair/head problem still holds for whatever proportions you choose.
Vilx-