Cropper.Blazor
1.2.5
See the version list below for details.
dotnet add package Cropper.Blazor --version 1.2.5
NuGet\Install-Package Cropper.Blazor -Version 1.2.5
<PackageReference Include="Cropper.Blazor" Version="1.2.5" />
paket add Cropper.Blazor --version 1.2.5
#r "nuget: Cropper.Blazor, 1.2.5"
// Install Cropper.Blazor as a Cake Addin #addin nuget:?package=Cropper.Blazor&version=1.2.5 // Install Cropper.Blazor as a Cake Tool #tool nuget:?package=Cropper.Blazor&version=1.2.5
Cropper.Blazor is a component that wraps around Cropper.js version 1.6.0
Demo
API
Prerequisites
- Supported .NET 7.0, .NET 6.0 versions for these web platforms:
- Blazor WebAssembly
- Blazor Server
- Blazor Server Hybrid with MVC
- MAUI Blazor Hybrid
Installation
dotnet add package Cropper.Blazor
Usage
Import Custom Element:
@using Cropper.Blazor.Components
Add the following to index.html
(client-side — Blazor Webassembly, Blazor MAUI) or _Host.cshtml
(server-side — Blazor Server, MVC with Blazor Server) in the head
<link href="_content/Cropper.Blazor/cropper.min.css" rel="stylesheet" />
Add the following to index.html
or _Host.cshtml
in the body
<script src="_content/Cropper.Blazor/cropper.min.js"></script>
Add the following to the relevant sections of Program.cs
using Cropper.Blazor.Extensions;
builder.Services.AddCropper();
In addition, you can change the path to the CropperJSInterop.min.js module if for some reason it is located outside the server root folder as follows:
- Override internal path to CropperJSInterop.min.js module:
builder.Services.AddCropper(new CropperJsInteropOptions()
{
DefaultInternalPathToCropperModule = "<YourPath>/_content/Cropper.Blazor/cropperJsInterop.min.js"
})
- Override full global path to CropperJSInterop.min.js module:
builder.Services.AddCropper(new CropperJsInteropOptions()
{
IsActiveGlobalPath = true,
GlobalPathToCropperModule = "<StartUrlWithPath>/_content/Cropper.Blazor/cropperJsInterop.min.js"
})
Also for server-side (Blazor Server or MVC with Blazor Server) you need add configuration SignalR, increase MaximumReceiveMessageSize of a single incoming hub message (default is 32KB) and map SignalR to your path. For example:
builder.Services.AddServerSideBlazor()
.AddHubOptions(options =>
{
options.MaximumReceiveMessageSize = 32 * 1024 * 100;
});
app.MapBlazorHub();
And then use it in Razor file (for example):
<CropperComponent
Class="cropper-demo"
ErrorLoadImageClass="cropper-error-load"
@ref="cropperComponent"
OnCropStartEvent="OnCropStartEvent"
OnCropEndEvent="OnCropEndEvent"
OnCropEvent="OnCropEvent"
OnZoomEvent="OnZoomEvent"
OnCropMoveEvent="OnCropMoveEvent"
OnReadyEvent="OnCropReadyEvent"
OnLoadImageEvent="OnLoadImageEvent"
Src="@Src"
InputAttributes="@InputAttributes"
ErrorLoadImageSrc="@ErrorLoadImageSrc"
IsErrorLoadImage="@IsErrorLoadImage"
OnErrorLoadImageEvent="OnErrorLoadImageEvent"
Options="options">
</CropperComponent>
And then use it in *.razor.cs file
You may override Cropper JavaScript module with execution script which can replace 6 event handlers (onReady, onCropStart, onCropMove, onCropEnd, onCrop, onZoom), such as overriding the onZoom callback in JavaScript:
window.overrideCropperJsInteropModule = (minZoomRatio, maxZoomRatio) => {
window.cropper.onZoom = function (imageObject, event, correlationId) {
const jSEventData = this.getJSEventData(event, correlationId);
const isApplyPreventZoomRatio = minZoomRatio != null || maxZoomRatio != null;
if (isApplyPreventZoomRatio && (event.detail.ratio < minZoomRatio || event.detail.ratio > maxZoomRatio)) {
event.preventDefault();
}
else {
imageObject.invokeMethodAsync('CropperIsZoomed', jSEventData);
}
};
};
Analysis of the signature onReady, onCropStart, onCropMove, onCropEnd, onCrop, onZoom event handlers:
imageObject
- Type:
Object
Reference to base cropper component.
event
- Type:
CustomEvent
Represent Cropper Event.
correlationId
- Type:
String
- Default:
Cropper.Blazor
A Correlation ID is a unique identifier that is added to the very first interaction(incoming request) to identify the context and is passed to all components that are involved in the transaction flow.
Definitely need to tell these rules in Blazor:
await JSRuntime!.InvokeVoidAsync("window.overrideCropperJsInteropModule", MinZoomRatio, MaxZoomRatio);
Contributing
- Fork it!
- Create your feature branch:
git checkout -b feature/<my-new-feature>
- Commit your changes:
git commit -m 'Add some feature'
- Push to the branch:
git push origin feature/<my-new-feature>
- Submit a pull request 😄
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 is compatible. 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. |
-
net6.0
- Microsoft.AspNetCore.Components.Web (>= 6.0.16)
-
net7.0
- Microsoft.AspNetCore.Components.Web (>= 7.0.5)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Cropper.Blazor:
Package | Downloads |
---|---|
Jarvis.Blazor.Mud
Biblioteca de componentes para MudBlazor. |
|
AlphaX.Blazor.Components.ImageCropper
This Blazor-based package integrates Radzen components with the powerful image cropping functionalities of CropperBlazor and Cropper.js. It offers a seamless and intuitive image cropping experience for Blazor applications, providing developers with ready-to-use components to implement and customize image editing features in their web applications. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.3.4 | 24,624 | 8/4/2024 |
1.3.2 | 19,665 | 3/30/2024 |
1.3.1 | 11,275 | 2/2/2024 |
1.3.0 | 6,506 | 11/18/2023 |
1.2.7 | 1,370 | 11/9/2023 |
1.2.6 | 3,439 | 10/8/2023 |
1.2.5 | 1,120 | 9/12/2023 |
1.2.4 | 876 | 7/24/2023 |
1.2.3 | 492 | 7/15/2023 |
1.2.2 | 548 | 6/23/2023 |
1.2.1 | 155 | 6/22/2023 |
1.2.0 | 4,373 | 5/1/2023 |
1.1.4 | 1,774 | 4/1/2023 |
1.1.3 | 896 | 2/27/2023 |
1.1.2 | 658 | 2/3/2023 |
1.1.1 | 609 | 11/24/2022 |
1.1.0 | 359 | 11/12/2022 |
1.0.2 | 552 | 11/3/2022 |
1.0.1 | 356 | 11/2/2022 |