graham23s
11-11-2007, 09:49 PM
Hi There guys
finished writing a function to resize uploaded images, it workes pretty well, but earlier i uploaded an image and because i'm resizing in % it was still pretty big, so i was going to set specific widths and heights (100w & 150h) instead of in %
is it better to resize in percentage or set height/widths would you say?
function resize_images($filename,$uploaddirectory,$var_loggedinuser) {
## Find out the files extension
$ext = explode(".", $filename);
$ext = $ext[count($ext)-1];
## Make all filenames lowercase
$ext = strtolower($ext);
if($ext == "jpg" || $ext == "jpeg")
$image = imagecreatefromjpeg($uploaddirectory);
elseif($ext == "png")
$image = imagecreatefrompng($uploaddirectory);
elseif($ext == "gif")
$image = imagecreatefromgif($uploaddirectory);
## save the file in %
$size = 0.50;
## rename the thumbnail
$newimagename_thumb = $var_loggedinuser. "-" .time();
$save = "thumbs/$newimagename_thumb.$ext";
## get the files dimensions
list($width,$height) = getimagesize($uploaddirectory);
## New measurements
$modwidth = $width * $size;
$modheight = $height * $size;
## Start making the image
$thumbnail = imagecreatetruecolor($modwidth, $modheight) ;
imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);
## Only return the image identified correctly
if($ext == 'jpg' || $ext == 'jpeg')
imagejpeg($thumbnail, $save, 100);
if($ext == 'gif')
imagegif($thumbnail, $save, 100);
if($ext == 'png')
imagepng($thumbnail, $save, 100);
return($newimagename_thumb. "." .$ext);
}
should i re-write this from scratch or is it easily modified to implement set width and height can anyone tell me?
thanks guys
Graham
finished writing a function to resize uploaded images, it workes pretty well, but earlier i uploaded an image and because i'm resizing in % it was still pretty big, so i was going to set specific widths and heights (100w & 150h) instead of in %
is it better to resize in percentage or set height/widths would you say?
function resize_images($filename,$uploaddirectory,$var_loggedinuser) {
## Find out the files extension
$ext = explode(".", $filename);
$ext = $ext[count($ext)-1];
## Make all filenames lowercase
$ext = strtolower($ext);
if($ext == "jpg" || $ext == "jpeg")
$image = imagecreatefromjpeg($uploaddirectory);
elseif($ext == "png")
$image = imagecreatefrompng($uploaddirectory);
elseif($ext == "gif")
$image = imagecreatefromgif($uploaddirectory);
## save the file in %
$size = 0.50;
## rename the thumbnail
$newimagename_thumb = $var_loggedinuser. "-" .time();
$save = "thumbs/$newimagename_thumb.$ext";
## get the files dimensions
list($width,$height) = getimagesize($uploaddirectory);
## New measurements
$modwidth = $width * $size;
$modheight = $height * $size;
## Start making the image
$thumbnail = imagecreatetruecolor($modwidth, $modheight) ;
imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);
## Only return the image identified correctly
if($ext == 'jpg' || $ext == 'jpeg')
imagejpeg($thumbnail, $save, 100);
if($ext == 'gif')
imagegif($thumbnail, $save, 100);
if($ext == 'png')
imagepng($thumbnail, $save, 100);
return($newimagename_thumb. "." .$ext);
}
should i re-write this from scratch or is it easily modified to implement set width and height can anyone tell me?
thanks guys
Graham