$ox = imagesx($im);
$oy = imagesy($im);
Не забывайте ставить ограничение:
$t = $ox / $oy;
if($t < 0.6) {exit();}
$t6x = ($ox / 140);
if($oy > $ox) {$nm = imagecreatetruecolor(140,100);
imagecopyresampled($nm, $im,0,0,0,($oy / 4),140,($oy / $t6x),$ox,$oy);}
else {$nm = imagecreatetruecolor(140,100);
imagecopyresampled($nm, $im,0,0,0,0,140,100,$ox,$oy);}