Here's my dilema. I have a box which is 315x210px, and a bunch of images of all kinda of random sizes, some with insane width/height ratios like 210:1, and others with ratios like 2:3, etc.
I'm trying to embed these images in the box and get them as close to 315x210px as possible, without messing up the aspect ratio.
I also don't want to use thumbnails, so I'm embedding the raw image, and using php to calculate the width/height and using css to hide the overflow.
My issue is that I've hit a wall and can't think of a more efficient way to do this. My current method isn't exactly efficient to begin with, so any help is appreciated.
The first if/while works fine to an extent, however I realized when making the second if/while that what I was doing was going to result in a server-crashing death loop. Hence, the second if was never actually finished, so I don't expect it to work. It's just there to show my concept.
I'm open to completely new ideas, but all I ask is that whatever it is doesn't involve creating and thumbnails. I want the original image to be the one that's embedded.
if($width_orig <= 315 && $height_orig <= 210){
while($newWidth <= 315 || $newHeight <= 210){
$newWidth = round($newWidth*1.2);
$newHeight = round($newHeight*1.2);
}
}
//This one was never intended to work. It's just for example.
else if($width_orig >= 315 && $height_orig >= 210){
while($newWidth >= 315 || $newHeight >= 210){
$newWidth = round($newWidth*1.2);
$newHeight = round($newHeight*1.2);
}
}
else
{
$newWidth = 315;
$newHeight = 210;
}