Chronos.Blazor.Cropper 1.2.16

dotnet add package Chronos.Blazor.Cropper --version 1.2.16                
NuGet\Install-Package Chronos.Blazor.Cropper -Version 1.2.16                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Chronos.Blazor.Cropper" Version="1.2.16" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Chronos.Blazor.Cropper --version 1.2.16                
#r "nuget: Chronos.Blazor.Cropper, 1.2.16"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Chronos.Blazor.Cropper as a Cake Addin
#addin nuget:?package=Chronos.Blazor.Cropper&version=1.2.16

// Install Chronos.Blazor.Cropper as a Cake Tool
#tool nuget:?package=Chronos.Blazor.Cropper&version=1.2.16                

Blazor.Cropper

Codacy Badge BCH compliance GitHub Nuget

A blazor library provide a component to crop image
alternate text is missing from this package README image=>
alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Sample site here
It is:

  • almost full c#
  • fast
  • mobile compatible
  • lighweight
  • support proportion
  • GIF crop support(only for small files)
  • support maui(blazor)
  • open source on github

If you find Blazor.Cropper helpful, you could star this repo, it's really important to me.

For a long time, crop image in blazor bother me a lot. That's why I tried to implement a cropper in blazor.

Users

  • CnGal CnGal是一个非营利性的,立志于收集整理国内制作组创作的中文Galgame/AVG的介绍、攻略、评测、感想等内容的资料性质的网站。

Maui Usage (new)

Blazor.Cropper now supports maui(blazor)!
In some platforms, you may need to use FilePicker to get the input image rather than using html input element. You can find details in the maui sample project

dotnet 6 changes

Although most of apis remains the same, there're some new apis which provide better performance in .Net 6.
In dotnet 5, using ImageCroppedResult.GetBase64Async(); to get the base64 result is fine. In dotnet 6, it should be replaced with ImageCroppedResult.GetDataAsync();, which may combined with new SetImageAsync(this IJSRuntime js,byte[] bin,string imgid) api to display the crop result.
You may find dotnet 6 sample here

Server-side Usage

Blazor.Cropper is designed to be a client side library. However, it can be used on server side blazor when setting PureCSharpProcessing="true".
Please note that using Blazor.Cropper on server side could consume remarkable amount of server resources(including bandwidth, cpu and memory).
Sample project

Quick Start

Only 4 steps to use Blazor.Cropper

Step0. Add nuget pkg

Install our nuget pkg at nuget.org. Add namespace to _import.razor:

@using Blazor.Cropper

Step1. Add script referrence

Then, you should paste following code into your index.html:

<script src="_content/Chronos.Blazor.Cropper/CropHelper.js"></script>

Step2. Add cropper

Just add cropper to your code. We recommend you to use it inside a modal card.

Example:

@* .... some code ...*@
<InputFile OnChange="OnInputFileChange"></InputFile>
<Cropper ImageFile="file" ></Cropper>
@* .... some code ...*@
    async Task OnInputFileChange(InputFileChangeEventArgs args)
    {
        file = args.File;
    }
@* .... some code ...*@
@* Example below shows how to bind Cropper with an InputFile component using InputId.
    Please note that you must set ImageFile property inorder to use gif crop or PureCSharpProcessing function.
    <InputFile id="input1"></InputFile>
    <Cropper InputId="input1" ></Cropper>
*@

Step3. Get result

To get the crop result, you need to get the reference of the Cropper, then call the Cropper.GetCropedResult() method.
Example:

@* .... some code ...*@
<Cropper ImageFile="file" @ref="cropper"></Cropper>
@* .... some code ...*@
@code{
    Cropper cropper;
    @* .... some code ...*@
    void GetCropResult()
    {
        var re = cropper.GetCropedResult();

        // in dotnet 6 or later
        var buffer = await re.GetDataAsync();
        // donot transfer bytes to base64 in dotnet 6.
        // if you want to display the crop result, use 
        // SetImageAsync(this IJSRuntime js,byte[] bin,string imgid) to
        // do the job



        // otherwise, get base64 directly
        // var base64 = await re.GetBase64Async();
    }
    @* .... some code ...*@
}

Api referrence

We have detailed xml comments on Cropper's properties & methods, simply read it while use it!
On the other hand, you can go to the sample project for usage examples.
To build it, simply clone it and run it in visual studio. The running result should be like this:
alternate text is missing from this package README image

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Chronos.Blazor.Cropper:

Repository Stars
CnGal/CnGalWebSite
CnGal是一个非营利性的,立志于收集整理国内制作组创作的中文Galgame/AVG的介绍、攻略、评测、感想等内容的资料性质的网站。
Version Downloads Last updated
1.2.16 13,642 8/20/2023
1.2.15 508 8/20/2023
1.2.14 19,642 1/5/2023
1.2.13 16,438 10/8/2022
1.2.12 8,263 9/19/2022
1.2.11 1,452 8/20/2022
1.2.10 885 8/17/2022
1.2.7 2,471 6/24/2022
1.2.6 1,351 6/15/2022
1.2.5 1,069 5/27/2022
1.2.4 815 5/27/2022 1.2.4 is deprecated because it has critical bugs.
1.2.3 901 5/25/2022 1.2.3 is deprecated because it has critical bugs.
1.2.2 8,651 3/17/2022
1.2.1 907 3/16/2022
1.2.0 2,885 11/12/2021
1.1.8 917 10/21/2021
1.1.7 789 10/17/2021
1.1.6 1,125 8/1/2021
1.1.5 798 8/1/2021
1.1.4 1,052 6/1/2021
1.1.2 1,328 11/18/2020
1.1.1 909 11/18/2020
1.1.0 851 11/18/2020
1.0.7 940 11/18/2020
1.0.6 816 11/18/2020
1.0.5 397 9/27/2020
1.0.4 269 9/26/2020
1.0.3 442 9/26/2020
1.0.2 246 9/21/2020
1.0.1 278 9/21/2020
1.0.0 292 9/20/2020