Well this should work from what I see. I trimmed things down a bit to all that was needed since we already call getimagesize. GD calls resize_jpeg function to create the images so here is all you need to add in bold.
Code:
Content visible to verified customers only.