Fixed "undefined function imagepng" error

Fixed "undefined function imagepng" error by checking if GD is enabled before saving png images.