Skip to content

UploadImage Component

The UploadImage component provides an image cropping interface in a modal window. It allows users to upload an image, adjust the crop area using drag and resize handles, and confirm the cropped result as a base64 image.

Props

Prop NameTypeDefaultDescription
showbooleanfalseControls visibility of the modal.
uploadSizenumber2Maximum allowed image size in MB.

Emits

Event NamePayloadDescription
onCloseEmitted when the modal is closed.
onCancelEmitted when the cancel button is clicked.
onResetEmitted when the reset button is clicked.
onCropstringEmitted when the crop is confirmed. The payload is a base64 image string.

Slots

This component does not use any slots.

Usage Example

vue
<template>
  <UploadImageModal
    :show="showModal"
    @onClose="showModal = false"
    @onCrop="handleCrop"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import UploadImageModal from '@/components/UploadImageModal.vue';

const showModal = ref(false);

const handleCrop = (croppedImage: string) => {
  console.log('Cropped Image:', croppedImage);
  showModal.value = false;
};
</script>

Screenshot

contentLayout image

Notes

  • Only PNG, JPG, JPEG, and WebP files are supported.
  • Minimum crop size is 50px by 50px.
  • Cropping box cannot exceed image boundaries.
  • Drag to move the crop box; use corner handles to resize.
  • Optional zoom functionality is available but commented out.