السلام عليكم لدي فنكشن اخواني الافاضل فى صفحة ادراج الخبر يقوم برفع الصورة اريد دمج به كود يقوم بتصغير حجم الصورة المرفوعه تلقائى بمعنى ان كانت 2 ميجا يصغر حجمها ل 400 كيلو بايل او 100 كيلو بالامتداد المرفوع
يعنى مثلا لو كانت jpg وحجمها 2 ميجا يصغرها ل 100 كيلو او اكثر بحيس اقدر احدد الحجم المهم لا يؤثر هذا على الرزليوشن الخاص بالصورة الفانكشن
<?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
}
}
?>