You must be more precise in your questions !
Again, what application are you refering to ?
Do you already have some code ?
If you define the width or height of the crop rectangle anywhere in your program limit their values, max or min.
Attached you find a modified version with min width and height.
The original examples above croped to a square (the original request), the project below crops a rectangle.
A more recent version ResizeAndCrop5 includes get the croped image and save it.