PHP'de resim küçültme



Mesaj önizleme 
 
Konuyu Değerlendir
  • 0 Oy - 0 Ortalama
  • 1
  • 2
  • 3
  • 4
  • 5
PHP'de resim küçültme
07-24-2010, 03:05 PM
Mesaj: #1
PHP'de resim küçültme
Aşağıda oluşturulmuş class' ı kullanarak sitenizde kullandığınız resimleri optimize ederek gösterebilirsiniz.

PHP Kod:
<?
class yThumb {

// find extension of file
function find_extension($file) {
$array explode('.',$file);
$key count($array) -1;
$ext $array[$key];
return 
$ext;
}

function 
thumb($image,$w,$h) {
if(
$this->find_extension($image) == 'jpg'$image_data imagecreatefromjpeg($image);
if(
$this->find_extension($image) == 'gif'$image_data imagecreatefromgif ($image);
if(
$this->find_extension($image) == 'png'$image_data imagecreatefrompng ($image);

// Original width && height
$width imagesx($image_data);
$height imagesy($image_data);

// Control width && and height
if(@$w 800 || @$h 800) {
$w$width$h$height;
}

if(@empty(
$w)) $w 140;
if(@empty(
$h)) $h 100;

$new imagecreatetruecolor($w$h);
imagecopyresampled($new$image_data0000$w$h$width$height);

// Finally, output..
if($this->find_extension($image) == 'jpg'$image_data imagejpeg($new);
if(
$this->find_extension($image) == 'gif'$image_data imagegif ($new);
if(
$this->find_extension($image) == 'png'$image_data imagepng ($new);

// Flush memory
imagedestroy($image_data);
imagedestroy($new);
}

}

$a = new yThumb();
$a->thumb("resim.jpg","998","584");


?>
Kullanıcının websitesini ziyaret et Bu kullanıcının gönderdiği tüm mesajları bul
Bu mesaji bir cevapta alıntı yap
Mesaj önizleme 


Foruma Git:


Bu konuyu görüntüleyen kullanıcı(lar): 1 Ziyaretçi

İletişim | Webmaster Forumu | En Üste Dön | İçeriğe Dön | Arşiv | RSS Beslemesi