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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -