Guest User

Untitled

a guest
Jun 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. function image_resize($originalImageResource, $maxWidth, $maxHeight){
  2. $newHeight = $maxHeight;
  3. $newWidth = $maxWidth;
  4. $oldHeight = imagesy($originalImageResource);
  5. $oldWidth = imagesx($originalImageResource);
  6. if (($oldWidth/$maxWidth)>($oldHeight/$maxHeight)){
  7. $ratio = $maxWidth/$oldWidth;
  8. $newWidth = $maxWidth;
  9. $newHeight = $oldHeight * $ratio;
  10. }else{
  11. $ratio = $maxHeight/$oldHeight;
  12. $newHeight = $maxHeight;
  13. $newWidth = $oldWidth * $ratio;
  14. }
  15. $newImage = imagecreatetruecolor($newWidth, $newHeight);
  16. imagecopyresampled(
  17. $newImage,
  18. $originalImageResource,
  19. 0, 0, 0, 0,
  20. $newWidth, $newHeight,
  21. $oldWidth, $oldHeight
  22. );
  23. return $newImage
  24. }
Add Comment
Please, Sign In to add comment