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 ;)
Expand|Select|Wrap|Line Numbers
- $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.";