Guest User

Untitled

a guest
Oct 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. <?php
  2.  
  3. $image = new JImage('/path/to/original.jpg');
  4.  
  5. $height = $image->getHeight();
  6. $width = $image->getWidth();
  7.  
  8. if ($height > $width) {
  9. $crop_square = $width;
  10. $crop_top = ($height - $width) / 2;
  11. $crop_left = 0;
  12. } else {
  13. $crop_square = $height;
  14. $crop_top = 0;
  15. $crop_left = ($width - $height) / 2;
  16. }
  17.  
  18. $image = $image->crop($crop_square, $crop_square, $crop_left, $crop_top, false);
  19.  
  20. $small = $image->resize(48, 48);
  21. $large = $image->resize(160, 160);
  22.  
  23. $small->toFile('/path/to/small.jpg');
  24. $large->toFile('/path/to/large.jpg');
Add Comment
Please, Sign In to add comment