How to rotate a image in C# and VB.NET

To rotate a image in C# and VB.NET you can use the following snippet.

Sample C#

public enum RotateMode
{
	Ninetee = 0,
	OneHundretEighty = 1,
	TwoHundredSeventy = 2,
}

public static Image RotateImage(Image myImage, RotateMode myRotatemode)
{
	var ret = myImage;
	switch (myRotatemode)
	{
		case RotateMode.Ninetee:
			ret.RotateFlip(RotateFlipType.Rotate90FlipNone);
			break;
		case RotateMode.OneHundretEighty:
			ret.RotateFlip(RotateFlipType.Rotate180FlipNone);
			break;
		case RotateMode.TwoHundredSeventy:
			ret.RotateFlip(RotateFlipType.Rotate270FlipNone);
			break;
	}
	return ret;
}

Sample VB.NET

Public Enum RotateMode
	Ninetee = 0
	OneHundretEighty = 1
	TwoHundredSeventy = 2
End Enum

Public Shared Function RotateImage(myImage As Image, myRotatemode As RotateMode) As Image
	Dim ret = myImage
	Select Case myRotatemode
		Case RotateMode.Ninetee
			ret.RotateFlip(RotateFlipType.Rotate90FlipNone)
			Exit Select
		Case RotateMode.OneHundretEighty
			ret.RotateFlip(RotateFlipType.Rotate180FlipNone)
			Exit Select
		Case RotateMode.TwoHundredSeventy
			ret.RotateFlip(RotateFlipType.Rotate270FlipNone)
			Exit Select
	End Select
	Return ret
End Function

How to flip a image in C# and VB.NET

To flip a image in C# and VB.NET you can use the following snippet.

Sample C#

public enum FlipMode
{
	Horizontal = 0,
	Vertical = 1,
	Both = 2
}

public Image FlipImage(Image myImage, FlipMode myFlipmode)
{
	var ret = myImage;
	switch (myFlipmode)
	{
		case FlipMode.Horizontal:
			ret.RotateFlip(RotateFlipType.RotateNoneFlipX);
			break;
		case FlipMode.Vertical:
			ret.RotateFlip(RotateFlipType.RotateNoneFlipY);
			break;
		case FlipMode.Both:
			ret.RotateFlip(RotateFlipType.RotateNoneFlipXY);
			break;
	}
	return ret;
}

Sample Vb.NET

Public Enum FlipMode
	Horizontal = 0
	Vertical = 1
	Both = 2
End Enum

Public Function FlipImage(myImage As Image, myFlipmode As FlipMode) As Image
	Dim ret = myImage
	Select Case myFlipmode
		Case FlipMode.Horizontal
			ret.RotateFlip(RotateFlipType.RotateNoneFlipX)
			Exit Select
		Case FlipMode.Vertical
			ret.RotateFlip(RotateFlipType.RotateNoneFlipY)
			Exit Select
		Case FlipMode.Both
			ret.RotateFlip(RotateFlipType.RotateNoneFlipXY)
			Exit Select
	End Select
	Return ret
End Function

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; 
}