Aşağıda oluşturulmuş class' ı kullanarak sitenizde kullandığınız resimleri optimize ederek gösterebilirsiniz.
<?
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_data, 0, 0, 0, 0, $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");
?>