All Projects → LazZiya → ImageResize

LazZiya / ImageResize

Licence: MIT license
Image resizing tool for .Net applications with ability to add text/image watermark, Supports animated images as well.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to ImageResize

imagor
Fast, Docker-ready image processing server in Go and libvips
Stars: ✭ 2,276 (+4957.78%)
Mutual labels:  crop-image, watermark
Imaginary
Fast, simple, scalable, Docker-ready HTTP microservice for high-level image processing
Stars: ✭ 4,107 (+9026.67%)
Mutual labels:  crop-image, watermark
Bimg
Go package for fast high-level image processing powered by libvips C library
Stars: ✭ 1,394 (+2997.78%)
Mutual labels:  crop-image, watermark
Configuration.Provider.Docker.Secrets
.NET Core configuration provider for Docker Secrets.
Stars: ✭ 20 (-55.56%)
Mutual labels:  asp-net-core
Database-First-ASP.Net-Core
Demo implementation of a Database First REST API in ASP.Net Core
Stars: ✭ 17 (-62.22%)
Mutual labels:  asp-net-core
Demo.AspNetCore.WebApi
Sample Web API powered by ASP.NET Core MVC, Azure Cosmos DB and MediatR
Stars: ✭ 24 (-46.67%)
Mutual labels:  asp-net-core
ProductsStoreOnKubernetes
Demoing deployment of Docker containers into Kubernetes for both minikube and Azure AKS.
Stars: ✭ 90 (+100%)
Mutual labels:  asp-net-core
CodeIndex
A Code Index Searching Tools Based On Lucene.Net
Stars: ✭ 28 (-37.78%)
Mutual labels:  asp-net-core
LyEditImageView
iOS Image Editor View
Stars: ✭ 20 (-55.56%)
Mutual labels:  crop-image
AspNetCoreMvcAngular
ASP.NET Core MVC with angular in MVC View OpenID Connect Hybrid Flow
Stars: ✭ 54 (+20%)
Mutual labels:  asp-net-core
RestWithASP-NETUdemy
No description or website provided.
Stars: ✭ 40 (-11.11%)
Mutual labels:  asp-net-core
CRUD.ASPCore.Reactjs.WebAPI.EF
CRUD Operations in ASP.NET Core application using React.js , Web API and Entity Framework core DB first approach with the help of VS 2017.
Stars: ✭ 80 (+77.78%)
Mutual labels:  asp-net-core
simple-blog-back
Back-End for Simple Blog
Stars: ✭ 36 (-20%)
Mutual labels:  asp-net-core
aspnetcore2aadauth
ASP.NET Core 2.0 Azure AD authentication example
Stars: ✭ 37 (-17.78%)
Mutual labels:  asp-net-core
high-performance-aspnet-core-workshop
Sample application used in the High-Performance ASP.NET Core Workshop
Stars: ✭ 29 (-35.56%)
Mutual labels:  asp-net-core
Blog.Core
Simple ASP.NET Core static blog engine
Stars: ✭ 15 (-66.67%)
Mutual labels:  asp-net-core
MediatR.AspNetCore.Endpoints
No description or website provided.
Stars: ✭ 89 (+97.78%)
Mutual labels:  asp-net-core
SimpleSocial
A simple social network web application using ASP.NET Core 3.1
Stars: ✭ 16 (-64.44%)
Mutual labels:  asp-net-core
I18N
I18N Library for .NET, and Delphi
Stars: ✭ 48 (+6.67%)
Mutual labels:  asp-net-core
NClient
💫 NClient is an automatic type-safe .Net HTTP client that allows you to call web service API methods using annotated interfaces or controllers without boilerplate code.
Stars: ✭ 25 (-44.44%)
Mutual labels:  asp-net-core

LazZiya.ImageResize

Image resizing tool for .Net applications, with support to add text/image watermark. This package is built on .NetStandard 2.0 so it supports wide range of compatible platforms (e.g. Asp.Net Core etc).

Docs

https://docs.ziyad.info

Release notes

Installation:

Install via nuget (enable Include prerelease to check for latest test versions):

Install-Package LazZiya.ImageResize

Resize image file

using System.Drawing;
using LazZiya.ImageResize;

using(var img = Image.FromFile(@"wwwroot\images\image-file.jpg"))
{
    img.ScaleByWidth(600)
       .SaveAs(@"wwwroot\images\resized-image.jpg");
}

Add text watermark and change color, opacity, ...etc.

AddTextWatermark method accepts argument of type TextWaterMarkOptions that allows to customize the text.

To change opacity of the text/outline/background just use the relevant Color with specified alpha value (0 - 255), 0 full opacity, 255 full color.

using(var img = Image.FromFile(@"wwwroot\images\image-file.jpg"))
{
    var tOps = new TextWatermarkOptions
    {
        // Change text color and opacity
        // Text opacity range depends on Color's alpha channel (0 - 255)
        TextColor = Color.FromArgb(50, Color.White),
        
        // Add text outline
        // Outline color opacity range depends on Color's alpha channel (0 - 255)
        OutlineColor = Color.FromArgb(255, Color.Black)
    };
    
    img.AddTextWatermark("http://ziyad.info", tOps)
       .SaveAs(@"wwwroot\images\new-image.jpg");
}

Add image watermark and change location, opacity, ...etc.

AddImageWatermark method accepts argument of type ImageWatermarkOptions that allows to specify watermark position etc.

using(var img = Image.FromFile(@"wwwroot\images\image-file.jpg"))
{
    var iOps = new ImageWatermarkOptions
    {
        // Change image opacity (0 - 100)
        Opacity = 50,
        
        // Change image watermark location
        Location = TargetSpot.BottomRight
    };
    
    img.AddImageWatermark(@"wwwroot\images\logo.png", iOps)
       .SaveAs(@"wwwroot\images\new-image.jpg");
}

Upload and resize an image

All ImageResize methods can be chained together to provide easy image processing. Below sample shows how to handle uploaded files, resize them, add image and text watermarks:

using System.Drawing;
using LazZiya.ImageResize;

foreach (var file in Request.Form.Files)
{
    if (file.Length > 0)
    {        
        using (var stream = file.OpenReadStream())
        {
            using(var img = Image.FromStream(stream))
            {
                img.ScaleAndCrop(800, 600)
                .AddImageWatermark(@"wwwroot\images\icon.png")
                .AddTextWatermark("http://ziyad.info")
                .SaveAs($"wwwroot\\images\\{file.FileName}");
            }
        }
    }
}

Supported resizing methods

All resizing methods will return a System.Drawing.Image file that can be saved in any supported image format (JPG, PNG, etc.)

  • Scale : Auto scales image by width or height, and keeps aspect ratio same as original image
img.Scale(800, 600);

// or 
img.Scale(800, 600, new GraphicOptions { ... });
  • Scale by width : Scales image by provided width value, auto adjusts new height according to aspect ratio.
img.ScaleByWidth(800);

// or 
img.ScaleByWidth(800, new GraphicOptions { ... });
  • Scale by height : Scales image by provided height value, auto adjusts new width according to aspect ratio.
img.ScaleByHeight(600);

// or 
img.ScaleByHeight(600, new GraphicOptions { ... });
  • 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);

// or
img.ScaleAndCrop(800, 600, new GraphicOptions { ... });

// or
img.ScaleAndCrop(800, 600, new GraphicOptions { ... }, TargetSpot.Center);
  • Crop : Directly crop a specified spot of the image, without scaling.
img.Crop(800, 600);

// or
img.Crop(800, 600, TargetSpot.Center);

// or
img.Crop(800, 600, new GraphicOptions { ... });

// or
img.Crop(800, 600, new GraphicOptions { ... }, TargetSpot.Center);

Adding Watermark

ImageResize supports adding text and image watermarks, both can be placed to any specified spot with ability to change opacity of the text or the image.

Add text watermark to the uploaded image

Below code will draw a colored text with a transparent background in the bottom left corner of the uploaded image:

img.AddTextWatermark("http://ziyad.info");

// or
img.AddTextWatermark("http://ziyad.info", new TextWatermarkOptions { ... });

Add image watermark and adjust opacity :

img.AddImageWatermark(@"wwwroot\images\logo.png");

// or
img.AddImageWatermark(@"wwwroot\images\logo.png", new ImageWatermarkOptions { ... });

// or
var wm = Image.FromFile(@"wwwroot\images\logo.png");
img.AddImageWatermark(wm);

// or
var wm = Image.FromFile(@"wwwroot\images\logo.png");
img.AddImageWatermark(wm, new ImageWatermarkOptions { ... });

TargetSpot :

Specifies that target spot used for cropping or placing text and image watermarks.

public enum TargetSpot { TopLeft, TopMiddle, TopRight, MiddleLeft, Center, MiddleRight, BottomLeft, BottomMiddle, BottomRight }

GraphicOptions

Define graphic options to ensure maximum image compatibility and quality. See GraphicOptions

TextWatermarkOptions

Define text watermark options, like locaiton, color, text outline, etc. See TextWatermarkOptions

ImageWatermarkOptions

Define image watermark option, lie location, opacity and margin. See ImageWatermarkOptions

goto project website: http://ziyad.info/en/articles/29-LazZiya_ImageResize

License

https://github.com/LazZiya/ImageResize/blob/master/LICENSE

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].