ط¯ط§ظ„ط© طھطµط؛ظٹط± ط§ظ„طµظˆط±



بسم الله الرحمن الرحيم

اليوم جبت لكم دالة لتصغير الصور

رمز PHP:
<code style="white-space:nowrap"> <code> function Resize_File($file, $directory, $max_width = 0, $max_height = 0)



{
global
$config;

$full_file = $directory.$file;

if (
eregi("\.png$", $full_file))
{
$img = imagecreatefrompng($full_file);
}

if (
eregi("\.(jpg|jpeg)$", $full_file))
{
$img = imagecreatefromjpeg($full_file);
}

if (
eregi("\.gif$", $full_file))
{
$img = imagecreatefromgif($full_file);
}

$FullImage_width = imagesx($img);
$FullImage_height = imagesy($img);

if (isset(
$max_width) && isset($max_height) && $max_width != 0 && $max_height != 0)
{
$new_width = $max_width;
$new_height = $max_height;
}
elseif (isset(
$max_width) && $max_width != 0)
{
$new_width = $max_width;
$new_height = ((int)($new_width * $FullImage_height) / $FullImage_width);
}
elseif (isset(
$max_height) && $max_height != 0)
{
$new_height = $max_height;
$new_width = ((int)($new_height * $FullImage_width) / $FullImage_height);
}
else
{
$new_height = $FullImage_height;
$new_width = $FullImage_width;
}

$full_id = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($full_id, $img, 0, 0, 0, 0, $new_width, $new_height, $FullImage_width, $FullImage_height);


if (
eregi("\.(jpg|jpeg)$", $full_file))
{
$full = imagejpeg($full_id, $full_file, 100);
}

if (
eregi("\.png$", $full_file))
{
$full = imagepng($full_id, $full_file);
}

if (
eregi("\.gif$", $full_file))
{
$full = imagegif($full_id, $full_file);
}

imagedestroy($full_id);
unset(
$max_width);
unset(
$max_height);
}
</code> </code>


طريقة استعمالها

Resize_File(&quot;original.jpg&quot;, 'images/', 100, 75);

مكان original.jpg تحط اسم الصورة

مكان images/ تحط اسم المجلد

وماكن 100 و 75

تغيره بالطول والعرض

ان اصبت فمن الله وان اخطأت فمن نفسي والشيطان









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