JoeAtRevolutionUnltd
Programmer
I have CMS and I am trying to have uploaded images width shrink to 228px and shrink the height relative to that width.
Here is the current code I am using. I have a set width and the code works, but I need to get rid of the height and have it change dynamicaly.
Can anyone help me out?
Thanks
Here is the current code I am using. I have a set width and the code works, but I need to get rid of the height and have it change dynamicaly.
Code:
$newwidth = 228;
$newheight = 163;
$cur_dir = "../uploads/products/";
$filename = $cur_dir.$cur_file;
if(preg_match("/.jpg/i", "$filename"))
{
$format = 'image/jpeg';
}
if (preg_match("/.gif/i", "$filename"))
{
$format = 'image/gif';
}
if(preg_match("/.png/i", "$filename"))
{
$format = 'image/png';
}
if($format!='')
{
list($width, $height) = getimagesize($filename);
switch($format)
{
case 'image/jpeg':
$source = imagecreatefromjpeg($filename);
break;
case 'image/gif';
$source = imagecreatefromgif($filename);
break;
case 'image/png':
$source = imagecreatefrompng($filename);
break;
}
$thumb = imagecreatetruecolor($newwidth,$newheight);
imagealphablending($thumb, false);
$source = @imagecreatefromjpeg("$filename");
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
$filename="$output_dir/$cur_file";
@imagejpeg($thumb, $filename);
Can anyone help me out?
Thanks