fix memory leak. We should call gdImageDestroy for free gdImagePtr