I am still trying to figure out what exactly it is you want it to do. At this time it seems like your script won't ever add the .gif extension. It reads the avatar-parameter, when it is not empty, .png will be added. When it is empty, .gif will be added. This won't ever work because the only case you will get .gif as output would be when there was no image inserted at all.
- if: works this way:
value if test string is not empty
If you want to check what extension avatar has, use }}} This will return the last 3 characters of avatar, which would be the png, jpg and gif suffixes. From there on, you can use these for if-statements or switch-cases, any way you prefer.
I feel I haven't answered your question yet, so I would like to see some more information on how you want to use this. Link to example pages where possible.