All pastes #482483 Raw Edit

Someone

public php v1 · immutable
·published 2007-05-11 08:58 UTC
rendered paste body
function cropImage($final_width, $final_height, $image, $w, $h) { //dest width, dest height, source image ressource, source width, source height	$final_image=(function_exists("imagecreatetruecolor"))?imagecreatetruecolor($final_width, $final_height):imagecreate($final_width, $final_height);	$wm = $w/$final_width;	$hm = $h/$final_height;	$h_height = $final_height/2;	$w_height = $final_width/2;	if($w> $h) {		$adjusted_width = $w / $hm;		$half_width = $adjusted_width / 2;		$int_width = $half_width - $w_height;		imagecopyresampled($final_image,$image,-$int_width,0,0,0,$adjusted_width,$final_height,$w,$h);	} elseif(($w <$h) || ($w == $h)) {		$adjusted_height = $h / $wm;		$half_height = $adjusted_height / 2;		$int_height = $half_height - $h_height;		imagecopyresampled($final_image,$image,0,-$int_height,0,0,$final_width,$adjusted_height,$w,$h);	} else {		imagecopyresampled($final_image,$image,0,0,0,0,$final_width,$final_height,$w,$h);	}	return $final_image;}