andrefarzat / ng-jcrop

Angular directive to jCrop jQuery plugin
GNU General Public License v2.0
101 stars 39 forks source link

get real selection pixels #64

Closed cescopag closed 7 years ago

cescopag commented 7 years ago

Hi, according to the demos, to pre-populate a selection area, I must use the "screen" pixels, not the scaled pixels. For example, in the first of your demo the image is 640x480 pixel and the selection is filled with 100, 100 in the source: $scope.obj.selection = [100, 100, 200, 200, 100, 100];

which are dynamically converted to the scaled values of 213, 213: x: 213 y: 213 x2: 427 y2: 427 w: 213 h: 213

The problem is: if I want to store the selection a user make, to let him modify his crop in the future, Is there a way to get those values? Let's say the user selects an area of 200 x 100 pixels in the same 640x480 image of the demo, the selection array will be populated with the scaled values, 426 x 213 pixels. But I need the original 200x100 pixels in order to preload the old crop area for the user to modify it.

Is there a way to do that? Or, alternatively, is there a way to set the initial selection with scaled values and not "screen" pixels, so that I can store the selection object directly?

andrefarzat commented 7 years ago

Hello, @cescopag. You're right about the "screen" size. I made a few tests here and jCrop converts the initial value to rationed value ( check the jcrop code here ).

To try to help you, I added the coords attribute to the ng-jcrop directive, so you have access to the "real" coords while the user is selecting. Check the demo site (the last example) : http://andrefarzat.github.io/ng-jcrop/

I just published the version 2.2.0 with this addition. If you need more, please reopen this issue 😸