Chronos.Blazor.Cropper
1.0.3
See the version list below for details.
dotnet add package Chronos.Blazor.Cropper --version 1.0.3
NuGet\Install-Package Chronos.Blazor.Cropper -Version 1.0.3
<PackageReference Include="Chronos.Blazor.Cropper" Version="1.0.3" />
paket add Chronos.Blazor.Cropper --version 1.0.3
#r "nuget: Chronos.Blazor.Cropper, 1.0.3"
// Install Chronos.Blazor.Cropper as a Cake Addin #addin nuget:?package=Chronos.Blazor.Cropper&version=1.0.3 // Install Chronos.Blazor.Cropper as a Cake Tool #tool nuget:?package=Chronos.Blazor.Cropper&version=1.0.3
Blazor.Cropper
A blazor library provide a component to crop image
=>
Live demo: http://49.234.6.167/cropper
It is:
- almost full c#
- fast
- mobile compatible
- lighweight
- support proportion
- GIF crop support(only for files smaller than 1mb)
- 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.
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)
{
<div class="modal is-active">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Modal title</p>
<button class="delete" aria-label="close" @onclick="()=>file=null"></button>
</header>
<section class="modal-card-body" style="overflow:hidden">
<Cropper MaxCropedHeight="500" MaxCropedWidth="500"
@ref="cropper"
Proportion="proportion==0?1:proportion"
RequireProportion="bool.Parse(enableProportion)"
InputId="input1"
ImageFile="file"
@bind-Ratio="ratio"
OnLoad="OnCropperLoad"></Cropper>
</section>
<footer class="modal-card-foot">
<button class="button is-success" @onclick="DoneCrop">Done</button>
@if (cropper!=null)
{
<input type="range" min="@(cropper.MinRatio*100)" max="@(cropper.MaxRatio*100)" value="@(ratio*100)" @oninput="OnRatioChange"/>
}
</footer>
</div>
</div>
}
<select @bind-value="enableProportion" @bind-value:event="onchange">
<option value="true">Enable proportion</option>
<option value="false">Disable proportion</option>
</select>
@if (bool.Parse(enableProportion))
{
<input type="number" @bind-value="proportion" placeholder="proportion"/>
}
@code {
Cropper cropper;
IBrowserFile file;
string imgUrl = "";
Image image;
string prompt = "Image cropped! Parsing to base64...";
bool parsing = false;
string enableProportion = "false";
double proportion = 1d;
double ratio = 1;
void OnRatioChange(ChangeEventArgs args)
{
ratio = int.Parse(args.Value.ToString())/100.0;
}
protected override void OnInitialized()
{
base.OnInitialized();
}
void OnInputFileChange(InputFileChangeEventArgs args)
{
image?.Dispose();
file = args.File;
}
void OnCropperLoad()
{
base.StateHasChanged();
}
async Task DoneCrop()
{
var args = await cropper.GetCropedResult();
file = null;
parsing = true;
base.StateHasChanged();
await Task.Delay(10);// a hack, otherwise prompt won't show
image?.Dispose();
await JSRuntime.InvokeVoidAsync("console.log", "converted!");
imgUrl = args.Base64;
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:
Product | Versions 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. |
-
net5.0
- Microsoft.AspNetCore.Components.Web (>= 5.0.0-rc.1.20451.17)
- SixLabors.ImageSharp (>= 1.0.1)
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,677 | 8/20/2023 | |
1.2.15 | 508 | 8/20/2023 | |
1.2.14 | 19,742 | 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,474 | 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.3 | 901 | 5/25/2022 | |
1.2.2 | 8,656 | 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 | 910 | 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 |