Türk Konsol

Bir portal blog (Teknoloji,oyun,haber,programlama,internet konuları) sitesi.

Haziran 15th, 2010

Resim boyutlandırma fonksiyonu

Php, php uygulamaları, by Emre Sarıoğlu.

Fonksiyon, php de resim boyutlandırmamızı sağlıyor.Üstelik resmi bozmadan yapıyor, resim boyutlandırma belirttiğimiz uygun boyuta göre belirleniyor.Fonksiyon aşağıdadır.

bu kodları boyutlandir.php olarak kaydediniz.. 
 
//Resmi Yeniden Boyutlandıran Fonksiyonumuz  
function boyutlandir($resim,$max_en,$max_boy)  
{  
ob_start();  
// Resmin Boyutunu Alıyoruz  
$boyut = getimagesize($resim);  
$en = $boyut[0];  
$boy = $boyut[1];  
 
// Boyut Oranlarını Belirliyoruz  
$x_oran = $max_en / $en;  
$y_oran = $max_boy / $boy;  
 
// Resmin Yeni Boyunu Orantılı Şekilde Ayarlıyoruz  
if (($en <= $max_en) and ($boy <= $max_boy))  
{  
$son_en = $en;  
$son_boy = $boy;  
} else if (($x_oran * $boy) < $max_boy) {  
$son_en = $max_en;  
$son_boy = ceil($x_oran * $boy);  
} else {  
$son_en = ceil($y_oran * $en);  
$son_boy = $max_boy;  
}  
 
// Resim Uzantısını Alıyoruz  
$uzantilar = pathinfo($resim);  
$uzanti = $uzantilar["extension"];  
 
if ($uzanti == 'gif')  
{  
$eski = imagecreatefromgif($resim);  
} elseif ($uzanti == 'png') {  
$eski = imagecreatefrompng($resim);  
} else {  
$eski = imagecreatefromjpeg($resim);  
}  
$yeni = imagecreatetruecolor($son_en,$son_boy);  
 
// Eski Resmi Yeniden Örneklendiriyoruz  
$renk = imagecolorallocate($yeni,255,255,255);  
imagefill($yeni,0,0,$renk);  
imagecopyresampled($yeni,$eski,0,0,0,0,$son_en,$son_boy,$en,$boy);  
 
// Yeni Resmi Tarayıcıya Yansıtıyoruz  
if ($uzanti == 'gif')  
{  
header("Content-type: image/gif");  
imagegif($yeni,null,100);  
} elseif ($uzanti == 'png') {  
header("Content-type: image/png");  
imagepng($yeni,null,100);  
} else {  
header("Content-type: image/jpeg");  
imagejpeg($yeni,null,100);  
}  
$icerik = ob_get_contents();  
 
// Temizlik  
ob_end_clean();  
imagedestroy($eski);  
imagedestroy($yeni);  
 
return $icerik;  
}  
define("UYERESIM_DIZIN",'images/urunler/'); 
 
function yol($Urun_ID,$url) 
{ 
 
  if (file_exists(UYERESIM_DIZIN.'/'.$url.'/'.$Urun_ID.'.jpg')) 
  { 
     $uye_resim = UYERESIM_DIZIN.'/'.$url.'/'.$Urun_ID.'.jpg'; 
  }elseif (file_exists(UYERESIM_DIZIN.'/'.$url.'/'.$Urun_ID.'.JPG')) { 
     $uye_resim = UYERESIM_DIZIN.'/'.$url.'/'.$Urun_ID.'.JPG'; 
  }elseif (file_exists(UYERESIM_DIZIN.'/'.$url.'/'.$Urun_ID.'.gif')) { 
     $uye_resim = UYERESIM_DIZIN.'/'.$url.'/'.$Urun_ID.'.gif'; 
  }elseif (file_exists(UYERESIM_DIZIN.'/'.$url.'/'.$Urun_ID.'.png')) { 
     $uye_resim = UYERESIM_DIZIN.'/'.$url.'/'.$Urun_ID.'.png'; 
  }else { 
    if ($url=='marka') { 
    $uye_resim = UYERESIM_DIZIN.'/markayok.gif'; 
    }else { 
    $uye_resim = UYERESIM_DIZIN.'/resimyok.gif'; 
    } 
  } 
 
 
return $uye_resim; 
 
} 
 
 
// resim_goster.html den Gelen Resim Değerlerini Alıyoruz  
$urunid = trim(strip_tags(htmlspecialchars($_GET['resim']))); //Resim Yolu ve Adını Alıyoruz 
$url = trim(strip_tags(htmlspecialchars($_GET['url']))); //Resim Yolu ve Adını Alıyoruz 
 
$resim= yol($urunid,$url); 
$en = intval($_GET['en']); // Resim Genişliği  
$boy = intval($_GET['boy']); // Resim Yüksekliği  
if (empty($en)) $en = 170;  
if (empty($boy)) $boy = 150;  
//Resmin Olup Olmadığını Kontrol Ediyoruz  
 
 
if ($resim && file_exists($resim))  
{  
//Fonksiyonu Çağırıyoruz  
echo boyutlandir($resim,$en,$boy); 
}

Back Top

Responses to “Resim boyutlandırma fonksiyonu”

Comments (0) Trackbacks (0) Leave a comment Trackback url
  1. No comments yet.
  1. No trackbacks yet.

Bir Cevap Yazın