Chronos.Blazor.Cropper 1.0.1

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.1
                    
NuGet\Install-Package Chronos.Blazor.Cropper -Version 1.0.1
                    
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.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Chronos.Blazor.Cropper" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Chronos.Blazor.Cropper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Chronos.Blazor.Cropper --version 1.0.1
                    
#r "nuget: Chronos.Blazor.Cropper, 1.0.1"
                    
#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.
#:package Chronos.Blazor.Cropper@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Chronos.Blazor.Cropper&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Chronos.Blazor.Cropper&version=1.0.1
                    
Install as a Cake Tool

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#(with only 3 lines of js)
  • 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"

<h1>Cropper</h1>
<InputFile OnChange="OnInputFileChange"></InputFile>
@if (!string.IsNullOrEmpty(imgUrl))
{
    <center>
        <h2>Crop Result:</h2>
        <img src="@imgUrl"/>
    </center>   
}
@if (file!=null)
{
    <Cropper ImageFile="file" OnCrop="@OnCropedAsync"></Cropper>
}
@code {
    IBrowserFile file;
    string imgUrl = "";
    void OnInputFileChange(InputFileChangeEventArgs args)
    {
        file = args.File;
    }
    async Task OnCropedAsync(Stream stream)
    {
        var bytes = new byte[stream.Length];
        await stream.ReadAsync(bytes,0,(int)stream.Length);
        var format = "image/png";
        imgUrl = $"data:{format};base64,{Convert.ToBase64String(bytes)}";
    }
}

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(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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 19,020 8/20/2023
1.2.15 537 8/20/2023
1.2.14 27,937 1/5/2023
1.2.13 16,600 10/8/2022
1.2.12 8,312 9/19/2022
1.2.11 1,501 8/20/2022
1.2.10 931 8/17/2022
1.2.7 3,266 6/24/2022
1.2.6 1,406 6/15/2022
1.2.5 1,124 5/27/2022
1.2.4 897 5/27/2022 1.2.4 is deprecated because it has critical bugs.
1.2.3 987 5/25/2022 1.2.3 is deprecated because it has critical bugs.
1.2.2 11,262 3/17/2022
1.2.1 961 3/16/2022
1.2.0 3,057 11/12/2021
1.1.8 977 10/21/2021
1.1.7 852 10/17/2021
1.1.6 1,194 8/1/2021
1.1.5 861 8/1/2021
1.1.4 1,227 6/1/2021
1.1.2 1,405 11/18/2020
1.1.1 992 11/18/2020
1.1.0 921 11/18/2020
1.0.7 1,012 11/18/2020
1.0.6 899 11/18/2020
1.0.5 468 9/27/2020
1.0.4 345 9/26/2020
1.0.3 516 9/26/2020
1.0.2 314 9/21/2020
1.0.1 352 9/21/2020
1.0.0 395 9/20/2020