Chronos.Blazor.Cropper 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Chronos.Blazor.Cropper --version 1.0.2
NuGet\Install-Package Chronos.Blazor.Cropper -Version 1.0.2
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.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Chronos.Blazor.Cropper --version 1.0.2
#r "nuget: Chronos.Blazor.Cropper, 1.0.2"
#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.0.2

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

Blazor.Cropper

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

It is:

  • almost full c#
  • mobile compatible
  • lighweight
  • support proportion
  • GIF crop support(only for files smaller than 1mb)

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

Usage

to use it, you should first paste following code into your index.html:

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

Then, you can install our nuget pkg and use it like follow:

@page "/cropper"
@inject IJSRuntime JSRuntime;

<h1>Cropper</h1>
<InputFile id="input1" OnChange="OnInputFileChange"></InputFile>
@if (parsing)
{
    <center>
        <h2>@prompt</h2>
    </center>
}
@if (!string.IsNullOrEmpty(imgUrl)&&!parsing)
{
    <center>
        <h2>Crop Result:</h2>
        <img src="@imgUrl" />
    </center>
}
@if (file != null)
{
    <Cropper InputId="input1" ImageFile="file" OnCrop="@OnCropedAsync"></Cropper>
}
@code {
    IBrowserFile file;
    string imgUrl = "";
    Image image;
    string prompt = "Image cropped! Parsing to base64...";
    bool parsing = false;
    void OnInputFileChange(InputFileChangeEventArgs args)
    {
        image?.Dispose();
        file = args.File;
    }
    async Task OnCropedAsync(ImageCroppedEventArgs args)
    {
        parsing = true;
        base.StateHasChanged();
        await Task.Delay(10);// a hack, otherwise prompt won't show
        image?.Dispose();
        await JSRuntime.InvokeVoidAsync("console.log", "converted!");
        image = args.Image;
        imgUrl = args.Image.ToBase64String(args.Format);
        parsing = false;
    }
}


For more details, see the sample project.
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

Note

In many cases, I found It's really slow to convert image data to base64 format and set it as img src in blazor(many times slower than image crop process). So I stronly recommend you to avoid doing this in blazor.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  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

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.16 7,452 8/20/2023
1.2.15 464 8/20/2023
1.2.14 14,124 1/5/2023
1.2.13 16,114 10/8/2022
1.2.12 8,237 9/19/2022
1.2.11 1,428 8/20/2022
1.2.10 860 8/17/2022
1.2.7 2,114 6/24/2022
1.2.6 1,321 6/15/2022
1.2.5 1,038 5/27/2022
1.2.4 788 5/27/2022
1.2.3 866 5/25/2022
1.2.2 7,441 3/17/2022
1.2.1 874 3/16/2022
1.2.0 2,805 11/12/2021
1.1.8 892 10/21/2021
1.1.7 763 10/17/2021
1.1.6 1,083 8/1/2021
1.1.5 771 8/1/2021
1.1.4 965 6/1/2021
1.1.2 1,301 11/18/2020
1.1.1 878 11/18/2020
1.1.0 827 11/18/2020
1.0.7 913 11/18/2020
1.0.6 786 11/18/2020
1.0.5 381 9/27/2020
1.0.4 254 9/26/2020
1.0.3 425 9/26/2020
1.0.2 231 9/21/2020
1.0.1 263 9/21/2020
1.0.0 276 9/20/2020