[ط¯ط§ظ„ط©] imageResize ظ„ط£ط¹ط§ط¯ط© طھط*ط¬ظٹظ… ط§ظ„طµظˆط±



بسم الله الرحمن الرحيم
النهاردة عملت دالة للresize للصور و قبل ما احطها هيا للأمتدادات gif , png و الjpg كل مرة الناس بتسأل فين باقي الامتدادات ؟؟؟
يا جماعة الامتدادات 3 دي مكتبة الgd بتقدم لهم الدعم الكامل يعني تقدر تعمل اي حاجة علي الصورة

المهم الدالة اهيه
اظن دي اقصر مرة اتكلم فيها


رمز PHP:
<code style="white-space:nowrap"> <code>

<?
/**
* Resize, cut and optimize image
* @Author Ahmed H AboElnasser
* @param array $sourceFile Image object from $_FILE
* @param string $destFile Destination filename
* @param integer $destWidth Desired width (optional)
* @param integer $destHeight Desired height (optional)
*
* @return boolean Operation result
*/
function imageResize($sourceFile, $destFile, $destWidth = NULL, $destHeight = NULL, $fileType = 'jpg')
{
if (!isset(
$sourceFile&#91;'tmp_name'&#93 OR !file_exists($sourceFile&#91;'tmp_name'&#93)
return
false;

list(
$sourceWidth, $sourceHeight, $type, $attr) = @getimagesize($sourceFile&#91;'tmp_name'&#93;
if (
$destWidth == NULL) $destWidth = $sourceWidth;
if (
$destHeight == NULL) $destHeight = $sourceHeight;

switch (
$type)
{
case
1:
$sourceImage = @imagecreatefromgif($sourceFile&#91;'tmp_name'&#93;
break;
case
2:
$sourceImage = @imagecreatefromjpeg($sourceFile&#91;'tmp_name'&#93;
break;
case
3:
$sourceImage = @imagecreatefrompng($sourceFile&#91;'tmp_name'&#93;
break;
default:



return
false;
}

$widthDiff = $destWidth - $sourceWidth;
$heightDiff = $destHeight - $sourceHeight;

if (
$widthDiff > 0 AND $heightDiff > 0)
{
$nextWidth = $sourceWidth;
$nextHeight = $sourceHeight;
}
else
{
if (
intval(Configuration::get('IMAGE_GENERATION_METHOD')) == 2 || (intval(Configuration::get('IMAGE_GENERATION_METHOD')) == 0 && $widthDiff > $heightDiff))
{
$nextHeight = $destHeight;
$nextWidth = intval(($sourceWidth * $nextHeight) / $sourceHeight);
$destWidth = (intval(Configuration::get('IMAGE_GENERATION_METHOD')) == 0 ? $destWidth : $nextWidth);
}
else
{
$nextWidth = $destWidth;
$nextHeight = intval($sourceHeight * $destWidth / $sourceWidth);
$destHeight = (intval(Configuration::get('IMAGE_GENERATION_METHOD')) == 0 ? $destHeight : $nextHeight);
}
}

$borderWidth = intval(($destWidth - $nextWidth) / 2);
$borderHeight = intval(($destHeight - $nextHeight) / 2);

$destImage = @imagecreatetruecolor($destWidth, $destHeight);

$white = imagecolorallocate($destImage, 255, 255, 255);
imagefill($destImage, 0, 0, $white);
imagecopyresampled($destImage, $sourceImage, $borderWidth, $borderHeight, 0, 0, $nextWidth, $nextHeight, $sourceWidth, $sourceHeight);
imagecolortransparent($destImage, $white);

return (
$fileType == 'gif' ? imagegif($destImage, $destFile) : ($fileType == 'png' ? imagepng($destImage, $destFile, 7) : imagejpeg($destImage, $destFile, 86)));
}
?>
</code> </code>










©المشاركات المنشورة تعبر عن وجهة نظر صاحبها فقط، ولا تُعبّر بأي شكل من الأشكال عن وجهة نظر إدارة المنتدى©