meta info
- Title: LazZiya.ImageResize - Resizing Methods
- Keywords: asp.net-core, image, resize, crop, scale, text watermark, animated, gif
- Description: Image resizing tool for .Net applications to resize images and add text/image watermark, Supports most common image types including animated gif.
- Author: Ziya Mollamahmut
- Date: 10-Feb-2021
- Image: https://github.com/LazZiya/Docs/raw/master/LazZiya.ImageResize/v4.0/images/lazziya-imageresize-logo.png
- Image-alt: LazZiya.ImageResize Logo
- Version: v4.0
- Scale : Auto scales image by width or height till both borders are fitted, and keeps aspect ratio same as the original image
using(var img = Image.FromFile("my-image.jpg"))
{
img.Scale(800, 600)
.SaveAs("resized-image.jpg");
}
- Scale by width : Scales image by provided width value, auto adjusts new height according to aspect ratio.
img.ScaleByWidth(800);
- Scale by height : Scales image by provided height value, auto adjusts new width according to aspect ratio.
img.ScaleByHeight(600);
- Scale and crop : Scalesthe image to fit new width or new height (which fits first), then crops out the rest of the image.
img.ScaleAndCrop(800, 600);
// or
img.ScaleAndCrop(800, 600, TargetSpot.Center);
- Crop : Directly crop a specified spot of the image, without scaling.
img.Crop(800, 600);
// or
img.Crop(800, 600, TargetSpot.Center);
- All resizing methods will return a
System.Drawing.Image
file that can be saved in any supported image format (JPG, PNG, etc.) - All methods can be overloaded with an optional parameter:
GraphicOptions
. TargtSpot
can be used to quickly select a predefined region of the image.