class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
more info about the class
$dir = "../images/albums/"; $album = $_POST['album']; $add = $_POST['add']; $b_dir = $dir.$album."/"; $aid = $_POST['aid']; $thumb_path = "../images/albums/$album/thumb/"; if($add == 1){ if (is_dir($b_dir)) { if ($dh = opendir($b_dir)) { $i = 1; while (($file = readdir($dh)) !== false) { $tes = explode(".", $file); $arr_tmp = explode(".",$file); $formato = array_pop($arr_tmp); if( "." == $file || ".." == $file){ continue; } elseif($tes[1] == "db") { continue; } $full_path = "../images/albums/$album/full/"; $normal_path = "../images/albums/$album/normal/"; $thumb_path = "../images/albums/$album/thumb/"; $file_pacth = "../images/albums/".$album."/".$file; // Instanciamos o objeto Upload $handle = new Upload($file_pacth); $handle->auto_create_dir = true; $handle->file_overwrite = true; $handle->file_auto_rename = false; $stamp_name = time(); // Definimos as configurações desejadas da imagem normal $handle->image_resize = true; $handle->image_ratio_y = false; $handle->image_x = 460; $handle->image_y = 320; $handle->image_watermark = '../images/watermark.png'; $handle->image_watermark_x = -10; $handle->image_watermark_y = -10; $handle->file_new_name_body = "$stamp_name"; $handle->file_name_body_add = '_normal'; $handle->image_ratio_crop = true; // Definimos a pasta para onde a imagem maior será armazenada $handle->Process($normal_path); $nome_da_imagem_normal = $handle->file_dst_name; $normal = $normal_path.$nome_da_imagem_normal; // Aqui nos devifimos nossas configurações de imagem do thumbs $handle->image_resize = true; $handle->image_ratio_y = false; $handle->image_x = 100; $handle->image_y = 75; $handle->image_contrast = 10; $handle->jpeg_quality = 100; $handle->file_new_name_body = "$stamp_name"; $handle->file_name_body_add = '_thumb'; $handle->image_ratio_crop = true; // Definimos a pasta para onde a imagem thumbs será armazenada $handle->Process($thumb_path); $nome_da_imagem_thumb = $handle->file_dst_name; $thumb = $thumb_path.$nome_da_imagem_thumb; $i++; } closedir($dh); if ($handle->processed) { //$adiciona = "INSERT INTO csm_galeria_fotos (fid,aid,titulo,descricao,thumb,img,full) VALUES('','".$aid."','".$titulo."','".$desc."','".$thumb."','".$normal."','".$full."')"; //mysql_query($adiciona) or die("Não Foi Possível Adicionar A Imagem!"); echo 'Operação realizada com sucesso!'; echo "$i".$file_pacth.""; } else { // Em caso de erro listamos o erro abaixo echo 'Erro encontrado!'; echo 'Erro: ' . $handle->error . ''; } } } }
exemple:
I have 37 pic in the folder, but the class just resize and crop 27 or less
it's my code, take a look!
thk!!