Bugfix: drawing picture in a gd larger than itself

Drawing into a graphics device larger than the picture itself would
crash the server. This was caused by the loop which gets pixel from
picture. It only stopped on boundary of gd.