2.4.0 • Published 1 year ago
@cloudparker/easy-cropperjs-svelte v2.4.0
easy-cropperjs-svelte
Use cropper js in svelte through CDN cropperjs library.
Install
npm i @cloudparker/easy-cropperjs-svelte --save-dev
Screenshot
Usage
<script lang="ts">
import EasyCropperjs from '@cloudparker/easy-cropperjs-svelte';
let easyCropperjsRef: EasyCropperjs | null = $state(null);
let clientWidth: number = $state(0);
let file: File | null = $state(null);
async function handleCrop() {
let data = await easyCropperjsRef?.crop({
outputWidth: 300,
outputFormat: 'webp',
outputQuality: 0.6,
outputType: 'file'
});
console.log('crop', data);
}
function handleCropResult(ev: CustomEvent) {
let base64ImageUrl: string = ev.detail;
// Use base64ImageUrl
}
async function getFile(url: string) {
var fileName = url.split('/').pop() || 'file.png';
let blob = await (await fetch(url)).blob();
var file = new File([blob], fileName, { type: blob.type });
return file;
}
async function init() {
file = await getFile('/sky-1.webp');
}
$effect(() => {
init();
});
</script>
<div>
<h1>Easy Cropperjs Svelte Demo</h1>
<div style="height: 500px;">
{#if file}
<EasyCropperjs
bind:this={easyCropperjsRef}
outputAspectRatio={1}
inputImageFile={file}
onCrop={handleCropResult}
/>
{/if}
</div>
<button onclick={handleCrop} style="margin-top:16px;">Crop</button>
</div>
2.3.0
1 year ago
2.0.3
1 year ago
2.2.0
1 year ago
2.0.2
1 year ago
2.4.0
1 year ago
2.1.0
1 year ago
2.0.1
1 year ago
2.0.0
1 year ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago
0.0.9
2 years ago
0.0.8
2 years ago
0.0.7
2 years ago
0.0.6
2 years ago
0.0.5
2 years ago
0.0.4
2 years ago
0.0.3
2 years ago
0.0.2
2 years ago
0.0.1
2 years ago