Image Crop

A canvas-based component for cropping images with zoom and pan support, providing a real-time cropped preview.

Samples

Rectangle Crop (1:1)

Standard rectangular cropping with zoom, pan, and padding controls.

Rectangle

Loading image bitmap...

0

<script>

1

  import { ImageCrop } from 'fluid-ui-svelte/components';

2

  import { onMount } from 'svelte';

3

  

4

  let bitmap = $state<ImageBitmap>();

5

6

  onMount(async () => {

7

    const response = await fetch('https://picsum.photos/id/10/800/600');

8

    const blob = await response.blob();

9

    bitmap = await createImageBitmap(blob);

10

  });

11

</script>

12

13

{#if bitmap}

14

  <ImageCrop sourceImage={bitmap} aspectRatio={{ x: 16, y: 9 }} />

15

{/if}

File Upload

Select a local image file to crop. Supports custom aspect ratios and colors.

Rectangle

Please select an image to start cropping

0

<script>

1

  import { ImageCrop } from 'fluid-ui-svelte/components';

2

  

3

  let uploadedBitmap = $state<ImageBitmap>();

4

  let resultImage = $state<string>();

5

6

  async function handleFileChange(event) {

7

    const file = event.target.files?.[0];

8

    if (file) {

9

      const blob = new Blob([file], { type: file.type });

10

      uploadedBitmap = await createImageBitmap(blob);

11

    }

12

  }

13

</script>

14

15

<input type="file" accept="image/*" onchange={handleFileChange} />

16

17

{#if uploadedBitmap}

18

  <ImageCrop 

19

    sourceImage={uploadedBitmap} 

20

    aspectRatio={{ x: 16, y: 9 }} 

21

    bind:resultImage 

22

  />

23

  

24

  {#if resultImage}

25

    <img src={resultImage} alt="Cropped result" />

26

  {/if}

27

{/if}