ui-cropper icon indicating copy to clipboard operation
ui-cropper copied to clipboard

1px difference between several cropped images' height

Open igniscom opened this issue 8 years ago • 12 comments

Hello,

I'm using the directive with the following options :

<ui-cropper image="file" result-image="fileProcessed" area-type="rectangle" canvas-scalemode="full-width" aspect-ratio="1.25" result-image-format="image/jpeg" result-image-size="400"></ui-cropper>

The resulting image should be 400x320px. However, sometimes it's resulting 400x319px.

Is there a reason for that, and a way to fix it ?

igniscom avatar Nov 16 '17 09:11 igniscom

are you sure that the one missing pixel is not hidden by overflow?

CrackerakiUA avatar Nov 16 '17 13:11 CrackerakiUA

I'm talking about the files' dimensions - after creating a file from the base64 - not how they are rendered in the brower (sorry, I didn't give you enough details).

igniscom avatar Nov 16 '17 14:11 igniscom

i never had this issue, can you present codepen? WIth your setup on my project, tested 5-6 different files and all was correct

CrackerakiUA avatar Nov 16 '17 15:11 CrackerakiUA

Here is the codepen : https://codepen.io/vincent_ignis/pen/pdLoLN/ Play with the selection and see the thumb dimensions. If the selection reaches the top left and top right corners, I get 319px height, not 320px (not everytime).

(Note: the picture in the codepen is 600x600, if you need to know)

Edit: maybe something about rounding numbers? (Math.round)

igniscom avatar Nov 21 '17 10:11 igniscom

Test I've made:

  • the issue happens sometimes when enlarging the selection to left and right area (do it, if it doesn't happens, move the selection up or down).
  • then, if you scale down the selection, keeping one of its side on the area side, the issue is still there.
  • resize or just move the selection (on an area side or not): no more issue.

(don't know if it can help)

igniscom avatar Nov 23 '17 16:11 igniscom

@igniscom @CrackerakiUA i had just posted a similar issue here #59 i just got on here to ask if @CrackerakiUA had figured it out and then I saw this one :D

JakeAi avatar Nov 28 '17 12:11 JakeAi

Yep, but no fix found right now. :/

igniscom avatar Nov 28 '17 13:11 igniscom

I tried looking into it and debug it myself but it was way too time consuming.

JakeAi avatar Nov 28 '17 13:11 JakeAi

I have same problem with rectangular cropping, i am trying to get 800x420 dimension. But my result is still in 800x419. What's the problem, how can i fix it ?

samnads avatar Dec 03 '17 20:12 samnads

@CrackerakiUA @igniscom any movement here?

JakeAi avatar Feb 15 '18 15:02 JakeAi

I don't have in plans to check this issue in near future. This is not touching any of my projects and I don't have allot free time at the moment.

CrackerakiUA avatar Feb 15 '18 15:02 CrackerakiUA

I added an option to the directive that allows the user to force the aspect ratio on rectangles; it seems to solve the problem of the 1px distortion on certain files.

(3076)

            aspectRatio: '=?',
            forceAspectRatio: '=',      // <---------------
            allowCropResizeOnCorners: '=?',`

(3287)

            `scope.$watch('areaType', function () {
                cropHost.setAreaType(scope.areaType, scope.forceAspectRatio);     // <-------------
                updateResultImage(scope);
            });`

(2899)

        // returns a string of the selection area's type
        this.getAreaType = function () {
            return theArea.getType();
        };

        this.setAreaType = function (type, force) {   //  <------------
            var center = theArea.getCenterPoint();
            var curSize = theArea.getSize(),
                curMinSize = theArea.getMinSize(),
                curX = center.x,
                curY = center.y;

(2920)

            if (type === 'square' || type === 'circle' || force === true) {    //   <----------
                forceAspectRatio = true;
                theArea.setForceAspectRatio(true);
            } else {
                forceAspectRatio = false;
                theArea.setForceAspectRatio(false);
            }

i-nottage avatar Jul 23 '18 18:07 i-nottage