fork(34) download
  1. <?php
  2.  
  3. $imageWidth = 1000;
  4. $imageHeight = 500;
  5. $ar = 1.25;
  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.02s 24448KB
stdin
Standard input is empty
stdout
Cropped: 625 x 500