Un formulaire d'upload d'image creant une miniature

WRInaute occasionnel
Bonjour a tous , est t'il possible de creer un formulaire Un formulaire d'upload d'image creant une miniature dans un dossier et enrgistrant l'image originale dans un second dossier ?

Je ne cherche pas forcement un scipt tout fait :p mais des piste ou des fonction php qui pourrait m'etre utiles !

Merci , Ronan :wink:
 
WRInaute passionné
Oui ça existe, en cherchant sur GG tu devrais trouver ça facilement.

Voilà mon script, à adapter pour ce que tu souhaites (possible de mettre ça dans une fonction par exemple, et là c'est limité au jpg uniquement), ... $ID_photo c'est le nom de la photo, a toi de mettre ce que tu veux, mais attention aux caractère spéciaux :

Code:
$tof_dir = "img_shoptype/";
			$tof = upload($HTTP_POST_FILES,0,$tof_dir,$ID_photo);
			
			//Creation du thumbnails :
			$larg = $larg_h = 200;
			$hauteur = $hauteur_h = 250;
			$thumbdir = '../img_shoptype/';
			$tof_dir = '..';			
			
		    if(substr(strtolower($tof),(strlen($tof)-4),4) == ".jpg" || substr(strtolower($tof),(strlen($tof)-5),5) == ".jpeg")
		    {
			  $src = imagecreatefromjpeg($tof_dir."/".$tof);
			  $taille = getimagesize($tof_dir."/".$tof);
			  
			  if ($taille[1]<$hauteur && $taille[0]<$largeur)
			  {
				  $hauteur = $taille[1];
				  $largeur = $taille[0];
			  }
			  else
			  {
				  $ratio_h = $hauteur_h/$taille[1];
				  $ratio_v = $larg_h/$taille[0];
				  
				  $ratio = $ratio_v < $ratio_h ? $ratio_v : $ratio_h;
				  
				  $largeur = round($taille[0] * $ratio);
				  $hauteur = round($taille[1] * $ratio);
			  }
			  
			  $img = imagecreatetruecolor($largeur,$hauteur);		
			  imagecopyresized($img,$src,0,0,0,0,$largeur,$hauteur,$taille[0],$taille[1]);
			  imagejpeg($img, $thumbdir."/".$ID_photo.".jpg");
			  			  
		    }

Y'a peut être mieux je ne sais pas, si qq'un à une remarque hésitez pas ;)
 
WRInaute accro
voila le mien :

Code:
function copier_image($photo,$nom_photo,$destination,$longueur_max,$hauteur_max)
{
 // ----extention --------
 $ext = explode(".", $nom_photo);
if(count($ext) > 1) $ext = strtolower(end($ext));
if (($ext=='jpg') or ($ext=='jpeg') or ($ext=='jpe'))
	{
	 $type='jpg';
	 $est_image='oui';
	}
else if ($ext=='gif')
	{
	 $type='gif';
	 $est_image='oui';
	}
else if ($ext=='png')
	{
	 $type='png';
	 $est_image='oui';
	}
else $est_image='non';

if ($est_image=='oui')
	{
	 // ----info de l'image
	 $size = GetImageSize($photo);
	 if ($type=='jpg') $src_im = ImageCreateFromJpeg($photo);
	 else if ($type=='gif') $src_im = ImageCreateFromGif($photo);
	 else if ($type=='png') $src_im = ImageCreateFromPng($photo);
	 $longueur_photo = $size[0];
	 $hauteur_photo = $size[1];
	 //----- si dimensions ok, la copier
	 if (($longueur_photo<$longueur_max) and ($hauteur_photo<$hauteur_max))
		{
		 if (copy($photo, $destination)) return true;
		 else return false;
		}
	 else
		{
			// ----modifier longueur
			 if ($longueur_photo > $longueur_max)
				{
				 $hauteur_photo=round(($longueur_max / $longueur_photo) * $hauteur_photo);
				 $longueur_photo=$longueur_max;
				}
			// ----modifier hauteur
			 if ($hauteur_photo > $hauteur_max)
				{
				 $longueur_photo=round(($hauteur_max / $hauteur_photo) * $longueur_photo);
				 $hauteur_photo=$hauteur_max;
				}
		 $dst_im = ImageCreateTrueColor($longueur_photo,$hauteur_photo);
		 ImageCopyResampled($dst_im,$src_im,0,0,0,0,$longueur_photo,$hauteur_photo,$size[0],$size[1]);
		
		 if (ImageJpeg($dst_im,$destination)) return true;
		 else return false;
		}
	}
	else message_admin_erreur("Attention : La photo n'est pas au format valide (jpg, gif, png). elle ne sera donc pas copiée");
}

à optimiser, lé programmé à la truelle :)
 
Discussions similaires
Haut