<?php
$imageWidth = 1000;
$imageHeight = 500;
$ar = 1.25;
if ($ar < 1) { // "tall" crop
$cropWidth = min($imageHeight * $ar, $imageWidth); $cropHeight = $cropWidth / $ar;
}
else { // "wide" or square crop
$cropHeight = min($imageWidth / $ar, $imageHeight); $cropWidth = $cropHeight * $ar;
}
echo "Cropped: $cropWidth x $cropHeight";
PD9waHAKCiRpbWFnZVdpZHRoID0gMTAwMDsKJGltYWdlSGVpZ2h0ID0gNTAwOwokYXIgPSAxLjI1OwoKaWYgKCRhciA8IDEpIHsgLy8gInRhbGwiIGNyb3AKICAgICRjcm9wV2lkdGggPSBtaW4oJGltYWdlSGVpZ2h0ICogJGFyLCAkaW1hZ2VXaWR0aCk7CiAgICAkY3JvcEhlaWdodCA9ICRjcm9wV2lkdGggLyAkYXI7Cn0KZWxzZSB7IC8vICJ3aWRlIiBvciBzcXVhcmUgY3JvcAogICAgJGNyb3BIZWlnaHQgPSBtaW4oJGltYWdlV2lkdGggLyAkYXIsICRpbWFnZUhlaWdodCk7CiAgICAkY3JvcFdpZHRoID0gJGNyb3BIZWlnaHQgKiAkYXI7Cn0KCmVjaG8gIkNyb3BwZWQ6ICRjcm9wV2lkdGggeCAkY3JvcEhlaWdodCI7Cg==