note 102746 deleted from function.imagecopyresampled by danbrown

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: vanadragos at yahoo dot com 

----

the first function to resize the image on the page is faulty

this is a better function that works and also has a second pass because  some images did not get trough properly in the first pass

function resizeImage($src, $w, $h) {

	// Get the current size
	$width = ImageSx($src);
	$height = ImageSy($src);

	// If one dimension is right then nothing to do
//	if($width <= $w || $height <= $h)
	//	return($src);

	// Calculate new size
	if(($w - $width) > ($h - $height)) { // use height
		$s = $h / $height;
		$nw = round($width * $s);
		$nh = round($height * $s);
	}
	else { // Use width
		$s = $w / $width;
		$nw = round($width * $s);
		$nh = round($height * $s);
	}

	// Return the new image
	$nwidth = $nw;
	$nheight = $nh;

	// If one dimension is right then nothing to do
//	if($width <= $w || $height <= $h)
	//	return($src);

	// Calculate new size
	if(($w - $nwidth) > ($h - $nheight)) { // use height
		$s = $h / $nheight;
		$nw = round($nwidth * $s);
		$nh = round($nheight * $s);
	}
	else { // Use width
		$s = $w / $nwidth;
		$nw = round($nwidth * $s);
		$nh = round($nheight * $s);
	}
	$im = ImageCreateTrueColor($nw, $nh);
	ImageCopyResampled($im, $src, 0, 0, 0, 0, $nw, $nh, $width, $height);
	return($im);

}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.