Берем директорию "img_med/", считываем все картинки и сохраняем уменьшенные копии в "img_med/img_sm/"  <?php 
 $dir="img_med/"; //берем директорию 
 $ar=array(); 
 $dh = opendir($dir); 
 while ($file_d = readdir($dh)) : 
 if ($file_d[0] != ".") //не выводим вложенные папки 
 { 
 array_push($ar, $file_d); //читаем все файлы в директории 
 } 
 endwhile; 
 closedir($dh); 
 sort($ar); //сортируем файлы по имени 
 for($i=413;$i<count($ar);$i++) { 
 $img=$ar[$i]; 
 resize_image('img_med/'.$img, 'img_med/img_sm/'.$img, 200, 90); 
 } 
 function resize_image($file, $out, $w = 200, $q = 90) { 
 if(empty($file) | empty($out)) return false; 
 $src = imagecreatefromjpeg($file); 
 $w_src = imagesx($src); 
 $h_src = imagesy($src); 
 $ratio = $w_src/$w; 
 $w_dest = round($w_src/$ratio); 
 $h_dest = round($h_src/$ratio); 
 $dest = imagecreatetruecolor($w_dest, $h_dest); 
 imagecopyresampled($dest, $src, 0, 0, 0, 0, $w_dest, $h_dest, $w_src, $h_src); 
 imagejpeg($dest, $out, $q); 
 imagedestroy($dest); 
 imagedestroy($src); 
 return true; 
 } 
 echo "dune3"; 
 ?>