You do it like this:
http://i.imgur.com/YnfT3uE.png
The only special case is if the hero is at the very upper, leftmost PIXEL and then moves perfectly diagonally up/left - which you solve by translating such a move to be up OR left (and similarly for the other corner pixel positions). It doesn't really matter because you'll end up (i.e. still find yourself) at the "pole" either way.