Added methods for encoding as png, gif, gd, gd2.