كثيرا ما يحب الناس ان يصنعو برنامج صور صغير خاص بهم
ولكن ما لاحظتة انهم لا ينعون مصغرات للصور .
بل يعضون الصورة مصغرة بتعديل لابعاد ولكنها تبقى نفس الحجم .
اليك هذا الكود الصغير بسطورة الكبير بمفعولة يقوم بهذا نيابة عنك واقوم الان باضافة ميزة الكتابة على الصور .....
تحياتي لكم
يمكنك الان صنع مصغرات لصورك ببساطة مع هذه الدالة الجميلة كل ما عليك هو تمرير التالي :
كود PHP:
//$entry is the variable w/ filename
//$path has the path to folder with thumbnails
//$src is the directory with originals
//$prefix is the thumbnail prefix
//$scale is the ammount to scale the original
//$qual is the Quality of the image
و بواسطة الكود التالي يتم تمرير المتغريرات الى الفنكشن .
كود PHP:
thumbbeshoo('thdsa.jpg','E:/c-drive/phpdev/www/ccsu/target','','','20','10');
والفنكشن هو التالي يمكنة وضعة في صفحة مستقلة وتعمل لها انكلود في اي صفحة لكي تستدعيها ومن ثم تطبيق الفنكشن متى شئت .
كود PHP:
function thumbbeshoo($entry,$src,$path,$prefix,$scale,$qual){
//JPG
if(eregi(".+\.jpe?g$",$entry)){
if(!file_exists("$path/$prefix".$entry)){
$src=ImageCreateFromJPEG("$src/$entry");
$org_h=imagesy($src);
$org_w=imagesx($src);
$scale=($scale/100);
$nwidth=round($org_w*$scale);
$nheight=round($org_h*$scale);
$img=imagecreate($nwidth,$nheight);
ImageCopyResized($img,$src,0,0,0,0,$nwidth,$nheight,$org_w,$org_h);
$new_src=($path.$prefix.$entry);
ImageJPEG($img,$new_src,$qual);
ImageDestroy($img);
ImageDestroy($src);
}//End check for exising thumbnail
}//End jpg check
//GIF
elseif(eregi(".+\.gif$",$entry)){
if(!file_exists("$path/$prefix".$entry)){
$src=ImageCreateFromGIF("$src/$entry");
$org_h=imagesy($src);
$org_w=imagesx($src);
$scale=($scale/100);
$nwidth=round($org_w*$scale);
$nheight=round($org_h*$scale);
$img=imagecreate($nwidth,$nheight);
ImageCopyResized($img,$src,0,0,0,0,$nwidth,$nheight,$org_w,$org_h);
$new_src=($path.$prefix.$entry);
ImageGIF($img,$new_src,75);
ImageDestroy($img);
ImageDestroy($src);
}//End check for exising thumbnail
}//end GIF check
//PNG
elseif(eregi(".+\.png$",$entry)){
if(!file_exists("$path/$prefix".$entry)){
$src=ImageCreateFromPNG("$src/$entry");
$org_h=imagesy($src);
$org_w=imagesx($src);
$scale=($scale/100);
$nwidth=round($org_w*$scale);
$nheight=round($org_h*$scale);
$img=imagecreate($nwidth,$nheight);
ImageCopyResized($img,$src,0,0,0,0,$nwidth,$nheight,$org_w,$org_h);
$new_src=($path.$prefix.$entry);
ImagePNG($img,$new_src,75);
ImageDestroy($img);
ImageDestroy($src);
}//End check for exising thumbnail
}
}
وقد تم ارفاق الكود ايضا ........