fork download
  1. <?php
  2.  
  3. $imageWidth = 1000;
  4. $imageHeight = 500;
  5. $ar = 0.8;
  6.  
  7. if ($ar < 1) { // "tall" crop
  8. $cropWidth = min($imageHeight * $ar, $imageWidth);
  9. $cropHeight = $cropWidth / $ar;
  10. }
  11. else { // "wide" or square crop
  12. $cropHeight = min($imageWidth / $ar, $imageHeight);
  13. $cropWidth = $cropHeight * $ar;
  14. }
  15.  
  16. echo "Cropped: $cropWidth x $cropHeight";
  17.  
Success #stdin #stdout 0.03s 25820KB
stdin
Standard input is empty
stdout
Cropped: 400 x 500