Resizing images with Aspect Ratio

images php coding issues or problems here.

Moderators: macek, egami, gesf

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » 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:
[php]<?php
// 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 */
?>[/php]

Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest

cron