This is exactly what the recent Client side image optimization enabled by default does. You can see the hook here:
One big warning, is that we are moving from jQuery.FileUpload to Uppy in this release, so there are currently two ways of doing everything regarding this.