PHP resize image proportionally with max width or weight -
there php script resize image proportionally max widht or height??
ex: upload image , original size w:500 h:1000. but, want resize thats max height width , height 500... script resize image w: 250 h: 500
all need aspect ratio. along these lines:
$fn = $_files['image']['tmp_name']; $size = getimagesize($fn); $ratio = $size[0]/$size[1]; // width/height if( $ratio > 1) { $width = 500; $height = 500/$ratio; } else { $width = 500*$ratio; $height = 500; } $src = imagecreatefromstring(file_get_contents($fn)); $dst = imagecreatetruecolor($width,$height); imagecopyresampled($dst,$src,0,0,0,0,$width,$height,$size[0],$size[1]); imagedestroy($src); imagepng($dst,$target_filename_here); // adjust format needed imagedestroy($dst);
you'll need add error checking, should started.
Comments
Post a Comment