advanced-cropper / vue-advanced-cropper

The advanced vue cropper library that gives you opportunity to create your own croppers suited for any website design
https://advanced-cropper.github.io/vue-advanced-cropper/
Other
931 stars 130 forks source link

Can't get the current zoom level #218

Closed Emaxoso closed 3 weeks ago

Emaxoso commented 1 year ago

I don't know if this is a bug or a missing feature. I am trying to get the current zoom of the cropper, since for security reasons I need to crop on the server side, I was trying to find the image scale size.

I'm using the next branch

Norserium commented 1 year ago

@Emaxoso, hello!

First of all, why do you need to get the current zoom? To get the selected area you need coordinates only, they represent that area.

const { coordinates } = this.$refs.cropper.getResult();

If you really need to get the current zoom, you should know that there is not concept of absolute zoom. There is the visibleArea property that represents the current visible area of an image.

Emaxoso commented 1 year ago

First of all, why do you need to get the current zoom? To get the selected area you need coordinates only, they represent that area.

I use the zoom to resize the image. First I do the cropping with the coordinates then I use the zoom to enlarge the image.

I was able to track the zoom by extending the Cropper component.

export default defineComponent({
    extends: Cropper,
    emits: ['scale'],
    watch: {
        src() {
            this.scale = 1.0;
        },
        scale() {
            this.$emit("scale", Math.round(this.scale * 1000) / 1000);
        }
    },
    data: () => ({
        scale: 1.0
    }),
    methods: {
        onManipulateImage(event, params = {}) {
            if (event && event.scale) {
                this.scale = Math.max(1, this.scale + 1 - event.scale.factor);
            }
            Cropper.methods.onManipulateImage.call(this, event, params);
        },
    },
});
Norserium commented 1 year ago

First I do the cropping with the coordinates then I use the zoom to enlarge the image.

@Emaxoso, I still don't get why? Should the following cases give the different result size? image image

It's pretty strange, because the cropped part is the same in both cases.

dala00 commented 1 year ago

I also want to get current zoom level. Because zoom level is specified by other indicator UI on our app. Or I want to 'specify' zoom level of cropper.

Norserium commented 1 year ago

@dala00, I assume you want to get something like this?

dala00 commented 1 year ago

Oh, yes!

Norserium commented 1 year ago

@dala00, @Emaxoso is this issue still actual?

dala00 commented 1 year ago

I changed library (needed for job then)