FIX 5284: Prevent crash for lager images.

Implemented check in GD that estimates the memory required to load the image and rejects larger images. Created lock files that remains after a large image has previously crashed GD.