Page 1 sur 1

script pour redimmensnionner image et taille maxi image

Posté : 12 sept. 2006, 14:00
par fabien_14
Bonjour,

J'ai mon script d'envoi d'image qui marche trés bien mais cependant je voudrai lui rajouter 2 option ....

1 - Control du poinds de l'image maxi a 600 Ko ca m'eviterai davoir des image de 8 MO ....
2 - Redimmensionnement de la taille de l'image a 600 Pixels (la miniature est deja generer par le script ... ca m'evitera d'avoir des photo de 1600*1200 pixel a afficher sur le site et de m'enregsitrer l'image en 600 pixels en PNG .... j'ai essayer de faire comme la miniature mais je me suis embrouiller dans les variables ...


Code : Tout sélectionner

$path_big = "image_up/photos_carnet"; $path_thumbs = "$path_big/mini"; //the new width of the resized image. $img_thumb_width = 100; // in pixel $extlimit = "yes"; //Do you want to limit the extensions of files uploaded (yes/no) //allowed Extensions $limitedext = array(".gif",".jpg",".png",".jpeg"); //check if folders are Writable or not //please CHOMD them 777 if (!is_writeable($path_thumbs)){ die ("Erreur: Le dossier <b>($path_thumbs)</b> n'est pas accessible"); } if (!is_writeable($path_big)){ die ("Erreur: Le dossier <b>($path_big)</b> n'est pas accessible"); } //if the for has submittedd//////////////////////////////// if (isset($_POST['submit'])){ foreach ($_FILES['imgfile']['tmp_name'] as $key => $value) { $file_tmp=$value;//nom reel de l'image $file_type = $_FILES['imgfile']['type'][$key]; $file_name = $_FILES['imgfile']['name'][$key]; $file_size = $_FILES['imgfile']['size'][$key]; //check file extension////////////////////// $ext = strrchr($file_name,'.'); $ext = strtolower($ext); if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { //echo "L'extension du fichier sélectionné n'est pas correcte. <br /><a href=\"#\">retour</a>"; exit(); } //get the file extension.///////////////////// $getExt = explode ('.', $file_name); $file_ext = $getExt[count($getExt)-1]; $sql = mysql_query(" INSERT INTO up_image2 SET nom_image ='$file_ext', id_auteur ='$id_auteur', rubrique = '$rubrique', description = 'blabla', id_parent = '15' ") or die( mysql_error()); //Recuperation du dernier id et renomage///////////////// $rand_name = mysql_insert_id(); //get the new width variable./////////////////////// $ThumbWidth = $img_thumb_width; //keep image type/////////////////////////////// if($file_size){ if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){ $new_img = imagecreatefromjpeg($file_tmp); }elseif($file_type == "image/x-png" || $file_type == "image/png"){ $new_img = imagecreatefrompng($file_tmp); }elseif($file_type == "image/gif"){ $new_img = imagecreatefromgif($file_tmp); } //list width and height and keep height ratio.////////////////////// list($width, $height) = getimagesize($file_tmp); $imgratio=$width/$height; if ($imgratio>1){ $newwidth = $ThumbWidth; $newheight = $ThumbWidth/$imgratio; }else{ $newheight = $ThumbWidth; $newwidth = $ThumbWidth*$imgratio; } $resized_img = imagecreatetruecolor($newwidth,$newheight); imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); //save image Imagepng ($resized_img,"$path_thumbs/$rand_name _mini.png"); ImageDestroy ($resized_img); ImageDestroy ($new_img); echo "<br>Image Thumb: <a href=\"$path_thumbs/$rand_name _mini.png\" target=\"_new\" >$path_thumbs/$rand_name _mini.png</a>"; } //envoyer la grosse image///////////////////// move_uploaded_file ($file_tmp, "$path_big/$aaa/$rand_name.$file_ext"); echo "<br>grosse image: <a href=\"$path_big/$rand_name.$file_ext\" target=\"_new\">$path_big/$rand_name.$file_ext</a>"; echo "<br /><h3>merci</h3>"; echo "<div class=\"alerte\">Merci <b><? $auteur ?></b>Merci</div>"; }} } ?>

Posté : 12 sept. 2006, 14:38
par fabien_14
Pour enregistrer la grosse image en 600 pixels

j'ai fait comme la miniature c a dire ceci :

Code : Tout sélectionner

/// MODIFICATION GROSSE IMAGE $ThumbWidth2 = $img_thumb_width2; //list width and height and keep height ratio GRANDE IMAGE .////////////////////// list($width, $height) = getimagesize($file_tmp); $imgratio=$width/$height; if ($imgratio>1){ $newwidth2 = $ThumbWidth2; $newheight2 = $ThumbWidth2/$imgratio; }else{ $newheight2 = $ThumbWidth2; $newwidth2 = $ThumbWidth2*$imgratio; } $resized_img2 = imagecreatetruecolor($newwidth2,$newheight2); imagecopyresized($resized_img2, $new_img, 0, 0, 0, 0, $newwidth2, $newheight2, $width, $height); //save image Imagepng ($resized_img2,"$path_big/3/$rand_name.png"); ImageDestroy ($resized_img2);
Mais j'obtiens une image noir .....