heya guys, im trying to take a variable input file and make a thumbnail so my gallery pageloads are lower. i want all the thumbnails to end up around 15ish kb, i know my current settings dont display that - im still testing.
it works on smaller files 250k, resizes to about 20ish k and 170k to about 3k, but i cant get it to resize bigger images and the while loop wont stop when the image reaches a certain size, i dont know where to go... pls help me debug this bugger ;)
it works on smaller files 250k, resizes to about 20ish k and 170k to about 3k, but i cant get it to resize bigger images and the while loop wont stop when the image reaches a certain size, i dont know where to go... pls help me debug this bugger ;)
Code:
$target_size=90000; // 7.5KB
$initial_size=$target_path.$newfile;
$filesize=filesize($initial_size);
$file=$target_path.$newfile;
$x=0;
$reduction=($filesize*5)/100;
$size = 0.9;
while($filesize>$target_size){
$x++;
$save = $target_path."thumb_".$newname.".jpg";
$file = $file;
header('Content-type: image/jpeg') ;
list($width, $height) = getimagesize($file) ;
$modwidth = $width * $size;
$modheight = $height * $size;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 90) ;
$file = $target_path."thumb_".$newname.".jpg";
$filesize=$filesize-$reduction;
$size=$size-0.05;
}
echo "resized $x times.";
Comment