Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function image_resize($originalImageResource, $maxWidth, $maxHeight){
- $newHeight = $maxHeight;
- $newWidth = $maxWidth;
- $oldHeight = imagesy($originalImageResource);
- $oldWidth = imagesx($originalImageResource);
- if (($oldWidth/$maxWidth)>($oldHeight/$maxHeight)){
- $ratio = $maxWidth/$oldWidth;
- $newWidth = $maxWidth;
- $newHeight = $oldHeight * $ratio;
- }else{
- $ratio = $maxHeight/$oldHeight;
- $newHeight = $maxHeight;
- $newWidth = $oldWidth * $ratio;
- }
- $newImage = imagecreatetruecolor($newWidth, $newHeight);
- imagecopyresampled(
- $newImage,
- $originalImageResource,
- 0, 0, 0, 0,
- $newWidth, $newHeight,
- $oldWidth, $oldHeight
- );
- return $newImage
- }
Add Comment
Please, Sign In to add comment