Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- Fits an image in a given box, scaling it up or down as needed, retaining the aspect ratio of the image
- Input:
- $width, the width of the box
- $heigth, the height of the box
- $img->width, the width of the image
- $img->height, the height of the image
- Output:
- $width, the width of the scaled image
- $height, the height of the scaled image
- */
- private function fitImageInBox(&$width,&$height,$img) {
- $ar=$img->width/$img->height;
- $newW=$height*$ar;
- $newH=$width/$ar;
- if($newW>$width) {
- $height=$newH;
- } else {
- $width=$newW;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement