Croppie icon indicating copy to clipboard operation
Croppie copied to clipboard

Cropping when rotating

Open chilipote opened this issue 7 years ago • 23 comments

Hi,

I would like to know, if it's a bug or something I did wrong : I added today the enableOrientation: true option. Working great, the image is rotating. Yay. But I have some troubles during cropping.

In some words : I'm having an image larger than higher. When I flip it to the right, the image become higher than larger. If I try to crop the bottom of the image, the result can be transparent. And because images are always better than words :

Here the image I want to upload : croppie_1

Then I flip it croppie_2

I select the bottom of the image croppie_3

And here the result croppie_4

Am I the only one who experienced that ? Let me know if it's not clear.

Last version of Croppie : 2.4.1 Google chrome Original dimension of the image : 1000 * 667 Viewport : 200 * 200 Boundary : 260 * 260

chilipote avatar Mar 13 '17 17:03 chilipote

I think, maybe I found the problem :

croppie.js, _getCanvas, line 993.

    if (right > self._originalImageWidth) {
      width = self._originalImageWidth - left;
      outWidth = width;
    }
    if (bottom > self._originalImageHeight) {
      height = self._originalImageHeight - top;
      outHeight = height;
    }

I think this check, right > self._originalImageWidth is wrong in rotate situation, what do you think ?

chilipote avatar Mar 13 '17 18:03 chilipote

I am having this issue too, commented those if statements and issue has gone :) Thanks !

INJumbo avatar Mar 26 '17 11:03 INJumbo

In my case those lines was like this

if ((left + width) > self._originalImageWidth) { width = self._originalImageWidth - left; outWidth = width; } if ((top + height) > self._originalImageHeight) { height = self._originalImageHeight - top; outHeight = height; }

INJumbo avatar Mar 26 '17 11:03 INJumbo

@INJumbo which version did you have ?

chilipote avatar Apr 03 '17 21:04 chilipote

+1

raykudo avatar May 20 '17 08:05 raykudo

Same issue for me, when rotating and moving vertically.

jlozanoher avatar May 23 '17 14:05 jlozanoher

#326 was believed to has resolved this issue, but it seems some people are still having it. I can't get it to happen myself.

I've used the rotation example on demo page, rotated, dragged to the bottom, and the resulting image seems to be correct. I've not made a release since 326 was merged in, so I'm just using the code in master to do so. Can anyone pull the latest code from master and confirm that this issue is a thing of the past?

thedustinsmith avatar Jul 14 '17 13:07 thedustinsmith

I think this is fixed. I don't reproduce anymore using the latest 2.5.0

antoinelorcy avatar Jul 19 '17 07:07 antoinelorcy

I can still reproduce this with both master and the 2.5.0. It only happens with enforceBoundary disabled and an image with an aspect ratio of something other than 1:1. It looks to me like the problem is that the original image's width and height are used during the final drawing calculation. If the image was rotated an odd multiple of 90 degrees, that means it is using the width as the height and vice versa. I'm able to fix this so far (I haven't tested it extensively yet) by adding the following to the end of the _rotate() function to swap the original values:

if ((deg % 180) !== 0) {
    var lastOriginalHeight = this._originalImageHeight;
    this._originalImageHeight = this._originalImageWidth;
    this._originalImageWidth = lastOriginalHeight;
}

@thedustinsmith, does that seem like the right way to fix this?

JonathonRichardson avatar Oct 19 '17 22:10 JonathonRichardson

having the same problem as above

Hesesses avatar Nov 26 '17 11:11 Hesesses

@JonathonRichardson solucion fixed it for me. Thank you :+1:

rickthewebdev avatar Nov 27 '17 09:11 rickthewebdev

Thanks to @JonathonRichardson.. it fixed for me to.

hikari82 avatar Dec 26 '17 09:12 hikari82

Thanks for all the feedback in this one guys. I believe this issue is fixed in 2.5.2. I can't recreate the issue using the rotate example in the demo page. 2.5.2 should be released soon.

thedustinsmith avatar Jan 09 '18 14:01 thedustinsmith

@bhavikvaishnani Can you provide a video demonstrating the issues, or steps to recreate the issue?

thedustinsmith avatar Jan 25 '18 15:01 thedustinsmith

For me the problem showed in Croppie v2.4.1. Playing with jsbin, v2.4.0 has the problem, earlier versions don't work with my example, and the problem no longer shows from v2.5.1.

Example link: http://jsbin.com/hulowasusi/edit

Steps:

  1. Rotate right.
  2. Drag dog all the way up so the eye is at the crop edge.
  3. Press result.
  4. Scroll down to see if the cropped image has a white area on the bottom.

mishavee avatar Jun 20 '18 06:06 mishavee

yup @mishavee the cropped dog does have a white area :( 👍 has this issue been solved ?

ghost avatar Mar 02 '19 14:03 ghost

@rohitPagal it seems like a regression (in 2.6.4). If i use https://raw.githubusercontent.com/Foliotek/Croppie/pre-2.5.2/croppie.min.js it works.

pbf79 avatar Mar 27 '19 13:03 pbf79

@mishavee thanks for your jsbin 👍

Bug still seems to occur in 2.6.3 and 2.6.4 unfortunately just for your information.

In 2.6.2 this bug is fixed, but i can't use this version in my code.

mrhaver avatar Jun 04 '19 15:06 mrhaver

it works fine on 2.4.1 at least

mjunaid720 avatar Jan 28 '20 10:01 mjunaid720

@mrhaver Have you decided this problem in 2.6.4?

vadymstebakov avatar May 01 '20 20:05 vadymstebakov

@thedustinsmith Bug still occur in 2.6.4. When I rotate in the bottom of the image. Here is a link: https://codepen.io/by_olegovichs/pen/LYVMNaY?editors=0010

vadymstebakov avatar May 01 '20 20:05 vadymstebakov

Hi guys. I am facing the same issue with 2.6.4.

https://github.com/Foliotek/Croppie/pull/711 fixed the issue for me.

tristanbenier avatar May 12 '20 09:05 tristanbenier

It is possible to expect fix (i have seen PR which should fix it) ? Thanks

martinduris avatar Jun 11 '20 13:06 martinduris