Skip to content

Maximum Call Stack exceed on cropping image #124

@muhammadnabeelmehmood

Description

@muhammadnabeelmehmood

When a user uploads an image, I convert it to base64 and then crop it.

Upload Image Code

const reader = new FileReader();
reader.onload = (event) => {
 this.uploadImage = event.target.result;
};
reader.readAsDataURL(e.target.files[0]);

Vue Cropper Component

<vue-cropper
                      ref="cropper"
                      :auto-crop="true"
                      :data="data"
                      :min-crop-box-height="150"
                      :min-crop-box-width="150"
                      :src="uploadImage"
                      :view-mode="3"
                      :zoom-on-wheel="false"
                      @crop="fixDimensionCrop"
                    />

On this function I'm getting an error maximum call stack exceed.

fixDimensionCrop(event) {
          
            let width = event.detail.width;
            let height = event.detail.height;

            if (
                width < this.minCroppedWidth
          || height < this.minCroppedHeight
          || width > this.maxCroppedWidth
          || height > this.maxCroppedHeight
            ) {
                this.$refs.cropper.setData({
                    width: Math.max(this.minCroppedWidth, Math.min(this.maxCroppedWidth, width)),
                    height: Math.max(this.minCroppedHeight, Math.min(this.maxCroppedHeight, height)),
                });
               
            }
        },

fixDimensionCrop function is being called when user resize crop canvas.

@Agontuk Kindly have a look at it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions