How to resize a image in PHP

To resize a image in PHP you can use the following snippet.

Sample PHP

function ImageResize($imageName, $tempName, $maxWidth, $maxHeight)
{
	$extension = explode(".", $imageName);
	$extension = $extension[count($extension)-1];
 
	if($extension == "jpeg" || $extension == "jpg")
	{
		$image = imagecreatefromjpeg($tempName);
	}
        elseif($extension == "gif")
	{
		$image = imagecreatefromgif($tempName);
	}
	elseif($extension == "png")
	{
		$image = imagecreatefrompng($tempName);
	}
	
	$Width = imagesx($image);
	$Height = imagesy($image);
 
	if($Width <= $maxWidth && $Height <= $maxHeight)
	{
		return $image;
	}
 
	if($Width >= $Height) 
	{
		$newWidth = $maxWidth;
		$newHeight = $newWidth * $Height / $Width;
	}
	else 
	{
		$newHeight = $maxHeight;
		$newWidth = $Width / $Height * $newHeight;
	}
 
	$image2 = imagecreatetruecolor($newWidth, $newHeight);
	imagecopyresampled($image2, $image, 0, 0, 0, 0, floor($newWidth), floor($newWidth), $Width, $Height);
	return $image2; 
}

Please rate this snippet

How to load image from web asynchron into picturebox in C# and VB.NET

To load image from web asynchron into picturebox in C# and VB.NET you can use the following snippet.

Sample C#

pictureBox1.WaitOnLoad = false;
pictureBox1.LoadAsync(@"https://upload.wikimedia.org/wikipedia/commons/3/3f/Fronalpstock_big.jpg");

Sample VB.NET

pictureBox1.WaitOnLoad = False
pictureBox1.LoadAsync("https://upload.wikimedia.org/wikipedia/commons/3/3f/Fronalpstock_big.jpg")

Please rate this snippet