By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,035 Members | 1,167 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,035 IT Pros & Developers. It's quick & easy.

Images and Aspect Ratio Help Needed

P: n/a
I'm trying to figure out how to write some php code that will allow me
to resize a .jpg image and maintain it's aspect ratio - any help or
idea's would be appreciated.

Thanks...

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
function thumbnail($image_path,$thumb_path,$image_name,$thu mb_width)
{
$src_img = imagecreatefromjpeg("$image_path/$image_name");
$origw=imagesx($src_img);
$origh=imagesy($src_img);
if ($origw>$origh)
{
$new_w = $thumb_width;
$diff=$new_w/$origw;
$new_h=$origh*$diff;
}
else
{
$new_h = $thumb_width;
$diff=$new_h/$origh;
$new_w=$origw*$diff;
}
$dst_img = imagecreatetruecolor($new_w,$new_h);

imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_ w,$new_h,imagesx($src_img)
,imagesy($src_img));
imagejpeg($dst_img, "$thumb_path/th_$image_name");
return true;
}
"Ralph Freshour" <ra***@primemail.com> wrote in message
news:ns********************************@4ax.com...
I'm trying to figure out how to write some php code that will allow me
to resize a .jpg image and maintain it's aspect ratio - any help or
idea's would be appreciated.

Thanks...

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.