Avatar Size Restraints
Posted: Tue Feb 14, 2012 8:38 am
Hello!
I just followed your avatar system tutorial and everything is working great, however, in my website I need the image to be constrained to 75px high. I'm wondering if perhaps, there's a way to constrain it to the height rather than the width..
I have more room to play on width, but the height is non-negotiable.
Ideally it'd be 75px high x max-width of 150px or so.
Is this possible?
I just followed your avatar system tutorial and everything is working great, however, in my website I need the image to be constrained to 75px high. I'm wondering if perhaps, there's a way to constrain it to the height rather than the width..
I have more room to play on width, but the height is non-negotiable.
Ideally it'd be 75px high x max-width of 150px or so.
Is this possible?
//updates the current users profile info function set_profile_info($email, $about, $location, $avatar){ $email = mysql_real_escape_string(htmlentities($email)); $about = mysql_real_escape_string(nl2br(htmlentities($about))); $location = mysql_real_escape_string($location); if (file_exists($avatar)){ $src_size = getimagesize($avatar); if ($src_size['mime'] === 'image/jpeg'){ $src_img = imagecreatefromjpeg($avatar); }else if ($src_size['mime'] === 'image/png'){ $src_img = imagecreatefrompng($avatar); }else if ($src_size['mime'] === 'image/gif'){ $src_img = imagecreatefromgif($avatar); }else{ $src_img = false; } if ($src_img !== false){ $thumb_width = 75; if ($src_size[0] <= $thumb_width){ $thumb = $src_img; }else{ $new_size[0] = $thumb_width; $new_size[1] = ($src_size[1] / $src_size[0]) * $thumb_width; $thumb = imagecreatetruecolor($new_size[0], $new_size[1]); imagecopyresampled($thumb, $src_img, 0, 0, 0, 0, $new_size[0], $new_size[1], $src_size[0], $src_size[1]); } imagejpeg($thumb, "{$GLOBALS['path']}/user_avatars/{$_SESSION['uid']}.jpg"); } } $sql = "UPDATE `users` SET `user_email` = '{$email}', `user_about` = '{$about}', `user_location` = '{$location}' WHERE `user_id` = {$_SESSION['uid']}"; mysql_query($sql); }