How to reduce programmatically the image uploaded by user?

How to reduce programmatically the image uploaded by user?

I need a function that will automatically reduce the pixel dimension to 800 x 600 pixels / 180 resolution or (approx. 1.37MB) of image uploaded by user from digital camera, for example, 2271 x 1704 pixels /180 resolution or approx. 11.1MB.

After the user selected the image, the function will able to detect if pixels is above 800x600, process the photo (crop/ reduce) and resume upload.

Need help...