Forum Moderators: coopster
function createthumb($current_name,$new_name,$new_w,$new_h)
{
$system=explode(".",$current_name);
if (preg_match("/jpg¦jpeg/",$system[1])){$src_img=imagecreatefromjpeg($current_name);}
if (preg_match("/JPG¦JPEG/",$system[1])){$src_img=imagecreatefromjpeg($current_name);}
if (preg_match("/GIF¦gif/",$system[1])){$src_img=imagecreatefromgif($current_name);}
if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($current_name);}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y)
{
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y)
{
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y)
{
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if (preg_match("/png/",$system[1]))
{
imagepng($dst_img,$new_name);
} else {
imagejpeg($dst_img,$new_name);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}