Bunlar, bu kod gerçekleştiren adımlar
- Kopya kaynak görüntü
- Görüntü boyutlarını hesaplar
- (Eğer maksimum yükseklik / genişlik belirtin) görüntüyü yeniden boyutlandırır
- Boy oranını muhafaza eder
- Writes destination image
This was created from a variety of code snippets
I've found here at php.net and other places on the web.
I take no credit for any of this code other than
putting the pieces together. http://www.php.net/manual/en/function.getimagesize.php
<?php
$source_pic = 'images/source.jpg';
$destination_pic = 'images/destination.jpg';
$max_width = 500;
$max_height = 500;
$src = imagecreatefromjpeg($source_pic);
list($width,$height)=getimagesize($source_pic);
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if( ($width <= $max_width) && ($height <= $max_height) ){
$tn_width = $width;
$tn_height = $height;
}elseif (($x_ratio * $height) < $max_height){
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}else{
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$tmp=imagecreatetruecolor($tn_width,$tn_height);
imagecopyresampled($tmp,$src,0,0,0,0,$tn_width, $tn_height,$width,$height);
imagejpeg($tmp,$destination_pic,100);
imagedestroy($src);
imagedestroy($tmp);
?>