Crop an Image to a Square with Exact Coordinates
AIGClub TeamShare
A square only requires equal width and height; a useful square also keeps the subject safe after an avatar, card, or marketplace applies its own mask.
Direct answer
Set the square side to the smaller source dimension. For a geometric center, put half of the long-side difference before the crop. A 2400 × 1600 landscape therefore uses side 1600, X = (2400 − 1600) ÷ 2 = 400, and Y = 0. Move X or Y when the subject is not centered, then verify the downloaded square in the actual destination.
Calculate the first rectangle
Landscape: side = source height; X = (source width − side) ÷ 2; Y = 0.
Portrait: side = source width; X = 0; Y = (source height − side) ÷ 2.
Round half-pixel results to whole-pixel coordinates and recheck the far edge.
Worked example: 2400 × 1600 landscape
Enter X 400, Y 0, width 1600, and height 1600. Expected output is exactly 1600 × 1600. The left and right exclusions are both 400 pixels; the top and bottom exclusions are zero.
Adjust for the subject and destination
If a face sits near X 1500, move the square right while keeping X + 1600 no greater than 2400. Preview a circular avatar mask separately and leave safe space around hair, text, logos, and corners.
Failure checks before generating
Reject negative X or Y, zero-sized sides, a side above 16384, or a far edge outside the source. For example, X 900 plus width 1600 ends at 2500 and fails on a 2400-pixel source.
Verification checklist
Confirm the output summary says 1600 × 1600 and open the downloaded file.
Inspect all four edges for clipped text, faces, or product details.
Test the real square or circular destination mask before deleting nothing from the original.
If delivery requires 512 × 512, resize the accepted square afterward rather than stretching it.
Frequently asked questions
- What if the longer-side difference is odd?
- Choose a whole-pixel offset on one side and accept a one-pixel imbalance, then verify both far edges remain inside the source.
- Why not resize a landscape directly to a square?
- Unlocking the ratio would distort the scene. A crop deliberately chooses which edge pixels to remove before a proportional resize.
- How much margin should a circular avatar keep?
- There is no universal number. Preview the destination mask and keep important features away from its boundary.