Reputation: 247
$ratio = 16/9;
$rat = $info[0] / $info[1];
if ($rat == $ratio){
$newimg = imagescale($newimg, 960, 540, IMG_BICUBIC); // this works
}
elseif ($rat > $ratio){
// here I want something like:
$newimg = imagescale($newimg, 'auto', 540, IMG_BICUBIC);
}
So how to scale only height to 540 and scale width automatically, keeping the aspect ratio?
Upvotes: 1
Views: 1735
Reputation: 19779
You could use $rat * 540
to keep the same ratio, instead of 'auto'
:
$newimg = imagescale($newimg, $rat * 540, 540, IMG_BICUBIC);
So, if ratio is 4/3
by example, the width will be: 540*4/3 = 720
.
If the ratio is 16/9
, 540*16/19 = 960
.
Upvotes: 2