<?php
$imageWidth = 1000;
$imageHeight = 500;
$ar = 0.8;
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";
PD9waHAKCiRpbWFnZVdpZHRoID0gMTAwMDsKJGltYWdlSGVpZ2h0ID0gNTAwOwokYXIgPSAwLjg7CgppZiAoJGFyIDwgMSkgeyAvLyAidGFsbCIgY3JvcAogICAgJGNyb3BXaWR0aCA9IG1pbigkaW1hZ2VIZWlnaHQgKiAkYXIsICRpbWFnZVdpZHRoKTsKICAgICRjcm9wSGVpZ2h0ID0gJGNyb3BXaWR0aCAvICRhcjsKfQplbHNlIHsgLy8gIndpZGUiIG9yIHNxdWFyZSBjcm9wCiAgICAkY3JvcEhlaWdodCA9IG1pbigkaW1hZ2VXaWR0aCAvICRhciwgJGltYWdlSGVpZ2h0KTsKICAgICRjcm9wV2lkdGggPSAkY3JvcEhlaWdodCAqICRhcjsKfQoKZWNobyAiQ3JvcHBlZDogJGNyb3BXaWR0aCB4ICRjcm9wSGVpZ2h0IjsK