Search code examples
image-processingrotationcropjcrop

Get new crop coordinates after rotation


I have a site where one of the features lets users rotate/crop images. I'm using the following tools: - Aspose for rotation - Jcrop

before rotation to 90 or -90 the crop coordinates are correct but after rotation those coordinates are no longer. I have tried to change the coordinates as follow :

newX -> croppingCoordinates.w - croppingCoordinates.y - 1 newY -> croppingCoordinates.x

Note that croppingCoordinates is the jcrop coordinate resulting from "onChange" jcrop event.

Any idea where the calculation are wrong ?!!

Thank you in advanced


Solution

  • I found i turn around that works for me, maybe it will help someone else. it's simply by adding trueSize Jcrop property when attaching the Jcrop method to the div. So when i have a rotated image by 90 degree i simply set width = height and vice verse. like the following code snippet:

    if (rotationDegree == 90 || rotationDegree == -90 ){
        w =  $('#myDiv').height();
        h = $('#myDiv').width();
        jQuery(function ($) {
                    $('#myDiv').Jcrop({
                        onChange: showCoords,
                        keySupport: false,
                        trueSize: [w, h]
                    }, function () {
                        jcrop_api = this;
                    });
                }); 
    }