Resize image using WebImage
A useful helper that will allow you to resize images from the file system. Handy for creating avatars on the fly on a user profile for example.
public class HelpersController
{
public void GetThumbnail(string img, int width, int height)
{
new WebImage(img)
.Resize(width, height, true, true)
.Crop(1, 1)
.Write();
}
}
To preserve aspect ration and prevent enlarging of the image set the last two parameters for .Resize to true.
.Resize(width, height, true, true)
Usage
<img src="@Url.Action("GetThumbnail", "Helpers", new { img = "/Images/BigImageToResize.png", width = 35, height= 35 })" />
Written by David Wimbley
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Mvc
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#