A fraction is not a shape, and that is why your square crops are not square
Any crop tool that works on a preview has the same problem to solve. The image on screen is a few hundred pixels wide; the original might be four thousand. The selection has to be recorded in a way that survives that gap, and the obvious answer is to store it as a proportion of the image: this box starts 20 percent across and is 40 percent wide. Scale-independent, resolution-independent, and correct.
It is correct right up until a ratio is involved. Take a 2000 by 1000 photo and a selection half the width and half the height. In fractions that is a perfect 0.5 by 0.5, which looks square written down. In pixels it is 1000 by 500, which is 2:1. The fractions are equal and the shape is not, because the axes have different lengths underneath them. A tool that constrains ratios in fraction space produces crops that are square in the numbers and visibly wrong on the screen, and the error grows with how far from square the original was.
So the constraint has to be applied in pixels. Convert the fractional selection to pixels using the image dimensions, adjust the width or height there to hit the target ratio, convert back. The step is small and easy to skip, and skipping it is why so many crop tools produce a 1080 by 1074 square that an upload check rejects for not being square.
Then there is the question of which way to adjust. A selection that is too wide for the target ratio can be fixed by narrowing it or by making it taller, and the second is a trap: the user drew that box, and growing it means growing past whatever edge they drew near. Shrinking the over-long side always stays inside the image, always keeps the region the user was looking at, and never surprises them by expanding into content they deliberately excluded. Recentring on the original midpoint keeps the subject where they put it.
The last piece is what cropping does to quality, which is nothing. Unlike resizing, a crop copies pixels one for one; there is no resampling, no interpolation, no softening. The only loss is the re-encode, and that is a choice of format rather than a consequence of cropping. This is worth knowing because it makes the order of operations matter: crop first and resize second, and you resample once. Do it the other way and you resample the whole picture in order to throw most of it away.