Resizing images with Aspect Ratio

images php coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
User avatar
Posts: 2257
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Tue Mar 30, 2004 2:56 pm

Well, "aspect ratio" is just a fancy way of saying "proportinate width and height", so you can figure this out on your own. For example, a 600x450 image has an aspect ratio of 600/450 = 4/3 = 1.3333333. So, if you have such an image and you want to resize it to a width of 150:
// a pretend image (usually this data will come from GD)
$image['width'] = 600;
$image['height'] = 450;

$aspect_ratio = $image['width'] / $image['height']; // 1.333333ish

$new_width = 200;
$new_height = $new_width / $aspect_ratio; // 150

/* your resize code goes here */

Post Reply