note 102746 added to function.imagecopyresampled

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
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);

}
----
Server IP: 69.147.83.197
Probable Submitter: 86.106.49.77
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php
Edit        -- https://master.php.net/note/edit/102746
Del: integrated  -- https://master.php.net/note/delete/102746/integrated
Del: useless     -- https://master.php.net/note/delete/102746/useless
Del: bad code    -- https://master.php.net/note/delete/102746/bad+code
Del: spam        -- https://master.php.net/note/delete/102746/spam
Del: non-english -- https://master.php.net/note/delete/102746/non-english
Del: in docs     -- https://master.php.net/note/delete/102746/in+docs
Del: other reasons-- https://master.php.net/note/delete/102746
Reject      -- https://master.php.net/note/reject/102746
Search      -- https://master.php.net/manage/user-notes.php
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.