Vue Image Cropper Component

1.3.8 · maintenance · verified Sun Apr 19

Vue-croppa is a straightforward, highly customizable, and mobile-friendly image cropping component specifically designed for Vue 2.0 applications. It enables users to select an image, move, zoom, and crop it directly within the browser, supporting touch gestures for mobile devices and handling EXIF orientation. The current stable version is 1.3.8. While the package has seen consistent bug fixes and minor feature additions (like `auto-sizing` and `passive` mode) in its 1.x series, its focus on Vue 2.0 suggests a maintenance cadence rather than active feature development for newer Vue versions. Its key differentiators include simplicity of use, extensive customization options via props, and built-in mobile support for common cropping interactions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes a Vue application with the croppa component. It demonstrates how to integrate the component, bind it with `v-model`, and programmatically access its API to generate and upload a cropped image as a Blob.

import Vue from 'vue';
import Croppa from 'vue-croppa';
import 'vue-croppa/dist/vue-croppa.css';

Vue.use(Croppa);

new Vue({
  el: '#app',
  template: `
    <div>
      <croppa v-model="myCroppa" :width="400" :height="400" :placeholder="'Drag & Drop or Click to Choose'" :quality="2"></croppa>
      <button @click="uploadCroppedImage">Upload Cropped Image</button>
    </div>
  `,
  data: {
    myCroppa: {}
  },
  methods: {
    uploadCroppedImage() {
      if (!this.myCroppa.hasImage()) {
        alert('Please choose an image first!');
        return;
      }
      this.myCroppa.generateBlob(
        blob => {
          // In a real application, you'd upload this blob to a server.
          // For demonstration, we'll just log its size and type.
          console.log('Generated Blob:', blob);
          console.log(`Type: ${blob.type}, Size: ${blob.size} bytes`);
          // Example: const formData = new FormData();
          // formData.append('image', blob, 'cropped-image.jpeg');
          // fetch('/upload', { method: 'POST', body: formData });
          alert('Image blob generated and logged to console!');
        },
        'image/jpeg',
        0.8
      ); // 80% compressed jpeg file
    }
  }
});

view raw JSON →