compression - Compressing images - get image size PHP -
i have script recursively loops through sub directories , compresses jpegs. print file size, before , after compression prints same number. script running is:
set_time_limit (86000); ob_implicit_flush(true); $main = "files"; function readdirs($main){ $dirhandle = opendir($main); while($file = readdir($dirhandle)){ $newfile = $main.'/'.$file; if(is_dir($newfile) && $file != '.' && $file != '..'){ readdirs($newfile); } else{ if($file != '.' && $file != '..' && stristr($newfile,'.jpg')) { //echo $newfile.'</br>'; $img = imagecreatefromjpeg($newfile); echo 'compressing '.$newfile.'... ('.filesize($newfile).' bytes) ('; imagejpeg($img,$newfile, 30); echo filesize($newfile).' bytes)...<br>'; for($k = 0; $k < 40000; $k++) echo ' '; // spaces fill browser buffer } } } }
and output is:
compressing files/1013/0079/3180/beautifully_renovated_garden_apartment_in_rehavia_7.jpg... (58666 bytes) (58666 bytes)... compressing files/1013/0088/0559/exquisite_stand_alone_house_in_givat_hamivtar_exceptional_views_3.jpg... (49786 bytes) (49786 bytes)... compressing files/1013/0088/0587/exquisite_stand_alone_house_in_givat_hamivtar_exceptional_views_6.jpg... (18994 bytes) (18994 bytes)... compressing files/1013/0138/4914/beautiful_4_rooms_apartment_with_views_to_the_old_city_2.jpg... (527801 bytes) (527801 bytes)... compressing files/1013/0208/0656/fevrier_2011_005.jpg... (35607 bytes) (35607 bytes)... compressing files/1013/0216/6078/beautiful_townhouse_in_the_heart_of_the_german_colony_00.jpg... (42509 bytes) (42509 bytes)... compressing files/1013/0217/1359/unique_luxurious_new_penthouse_in_the_heart_of_the_german_colony_028.jpg... (1101251 bytes) (1101251 bytes)... compressing files/1013/0269/0299/exclusive_duplex_penthouse_in_the_german_colony_0171.jpg... (20912 bytes) (20912 bytes)... compressing files/1013/0821/0299/beautiful_views_to_the_knesset_and_gan_saker_016.jpg... (570428 bytes) (570428 bytes)... compressing files/1013/0822/0660/beautiful_new_penthouse_in_luxurious_building_with_pool_158double.jpg... (1020561 bytes) (1020561 bytes)... compressing files/1013/0847/8190/new_luxurious_penthouse_with_private_entrance_in_old_katamon_016.jpg... (542071 bytes) (542071 bytes)... ... ... ...
can tell me problem is? why size not updating?
thanks lot!
filesize()
uses caching mechanism (the "stat cache") may not have enough time refresh in between 2 calls.
use clearstatcache()
force cache refresh.
Comments
Post a Comment