How do you change the max height and width of upload images?

I have a client that is creating a media library for vendors. Everything is fine, but I need its not uploading a file once it exceeds a certain physical dimension (not overall size).

So I need to set the max height/width at 5000px.

I prefer to change this via a function if possible.