I don't think you need to do coding for your requirement. You can take help from this documentation for same - https://drupal.org/node/22271. It says for D7 :
Enable user pictures for Drupal 7
- Navigate to Configuration > People > Account settings.
- In the Personalization settings, select Enable user pictures.
- For Picture directory type pictures
- Under Picture display style, select thumbnail (you can change the size settings
- Click "Save configuration".
Next, ensure your user pictures display in your theme. These are enabled by default in Bartik, the default theme of Drupal 7 , so you may have to check this with any new theme you add.
- Go to Appearance and click "Settings" for the theme you have enabled as default.
- In the Toggle display settings, select User pictures in posts and/or User pictures in comments.
- Click "Save configuration".
If your theme doesn't support user pictures, then you should look for bartik & apply same structure for TPL.