Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add cross-origin image loading example #265

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,21 @@
</SectionContent>
</DocsPageSection>

<DocsPageSection>
<SectionHeader Title="Load cross-origin image">
<Description>
A cross origin image with a <MudLink UserAttributes="@(new Dictionary<string, object>(){ {"rel", "noopener"} })" Target="_blank" Href="https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin">crossorigin</MudLink> attribute and an available Access-Control-Allow-Origin response header can be cropped by <span style="color: var(--mud-palette-primary)"><b>Cropper.Blazor</b></span>.
If you try to start cropper on a cross-origin image, please make sure that your browser supports
<MudLink UserAttributes="@(new Dictionary<string, object>(){ {"rel", "noopener"} })" Target="_blank" Href="https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes">HTML5 CORS settings attributes</MudLink>,
and your image server supports the Access-Control-Allow-Origin option (see the <MudLink UserAttributes="@(new Dictionary<string, object>(){ {"rel", "noopener"} })" Target="_blank" Href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS">HTTP access control (CORS)</MudLink>).
<br><br>
If your image isn't be a cross-origin, set the <CodeInline>CheckCrossOrigin</CodeInline> in the <CodeInline><MudLink UserAttributes="@(new Dictionary<string, object>(){ {"rel", "noopener"} })" Target="_blank" Href="/contract/Options">Options</MudLink></CodeInline> property to <CodeInline>false</CodeInline>.
</Description>
</SectionHeader>
<SectionContent Code="LoadCrossOriginImageExample">
<LoadCrossOriginImageExample />
</SectionContent>
</DocsPageSection>

</DocsPageContent>
</DocsPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@using Cropper.Blazor.Models

<div class="img-container">
<CropperComponent Src="cropperblazor.png" Options="options" InputAttributes="InputAttributes" />
</div>

<style>
.img-container {
max-height: 300px;
width: 100%;
}
</style>

@code {
private Options options;

public Dictionary<string, object> InputAttributes { get; set; } = new Dictionary<string, object>
{
{ "crossorigin", "anonymous" } // Another possible values: "use-credentials" or "" (the same as "anonymous"). An invalid keyword and an empty string will be handled as the anonymous keyword. For more information see official https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin documentation
};

protected override void OnInitialized()
{
options = new Options
{

};
}
}
Loading