الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مشكلة بتصغير حجم الصور عند الرفع

بدأه fatmaali في 27 يونيو 2013 · 1 رد · 477 مشاهدة · في منتدى تطوير المواقع بـ PHP
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

لقد طرحت السؤال سابقاً لكن لم يكتمل الرد والموضوع مهم جدا فياليت لو فى حد يساعدني

 

 

بدي ادمج كود يتماشا مع هذا الفنكشن يقوم بعمل تصغير مساحة الصور بدون التاثير على الابعاد

<?php

if(isset($_POST['action'])){
$idir = "pic/";   // Path To Images Directory
$tdir = "pic/";


$url = $_FILES['my_files']['name'];
$nomOrigine = $_FILES['my_files']['name'];
$elementsChemin = pathinfo($nomOrigine);
$extensionFichier = strtolower($elementsChemin['extension']);  // Set $url To Equal The Filename For Later Use

    $file_ext = strrchr($_FILES['my_files']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php
    $copy = copy($_FILES['my_files']['tmp_name'], "$idir" . $_FILES['my_files']['name']);   // Move Image From Temporary Location To Permanent Location
    if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location
      print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image
       $nomDestination = "Img_".date("YmdHis").".".$extensionFichier;
	   
	   if($extensionFichier == 'jpg'){$destination = imagecreatefromjpeg("$idir" . $url);}
	   else if($extensionFichier == 'gif'){$destination = imagecreatefromgif("$idir" . $url);}
	    else if($extensionFichier == 'png'){$destination = imagecreatefrompng("$idir" . $url);}
		 else if($extensionFichier == 'jpeg'){$destination = imagecreatefromjpeg("$idir" . $url);}

		 
	     // Make A New Temporary Image To Create The Thumbanil From
      $largeur_destination = imagesx($destination);   // Current Image Width
      $hauteur_destination = imagesy($destination);   // Current Image Height

	  $nomDestination = "Img_".date("YmdHis").".".$extensionFichier;
	  
	  
	  
	  if($largeur_destination>1200){$source = imagecreatefrompng("logo2.png");}
	  else if($largeur_destination<=1200 && $largeur_destination>500){$source = imagecreatefrompng("logo.png");}
	  else if($largeur_destination<=500){$source = imagecreatefrompng("logo3.png");}
	   // Le logo est la source
	   

// Les fonctions imagesx et imagesy renvoient la largeur et la hauteur d'une image
$largeur_source = imagesx($source);
$hauteur_source = imagesy($source);


//

// On veut placer le logo en bas ? droite, on calcule les coordonn?es o? on doit placer le logo sur la photo
$destination_x = $largeur_destination - $largeur_source;
$destination_y =  $hauteur_destination - $hauteur_source;





	  
	 imagecopymerge($destination, $source, $destination_x, $destination_y, 0, 0, $largeur_source, $hauteur_source, 60);
   // Copy Resized Image To The New Image (So We Can Save It)
   	   if($extensionFichier == 'jpg'){ imagejpeg($destination, "$tdir" . $nomDestination); }
	   else if($extensionFichier == 'gif'){ imagegif($destination, "$tdir" . $nomDestination); }
	    else if($extensionFichier == 'png'){ imagepng($destination, "$tdir" . $nomDestination); }
		 else if($extensionFichier == 'jpeg'){ imagejpeg($destination, "$tdir" . $nomDestination); }
		 
        // Saving The Image
	      imagedestroy($destination);   // Destroying The Temporary Image
      imagedestroy($source);  
	   unlink ("$idir" . $_FILES['my_files']['name']);

      print 'تم رفع الصورة';   // Resize successful
    } 
}
?>

مواضيع مشابهة