andrefarzat / ng-jcrop

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

trueSize #2

Closed deecodameeko closed 9 years ago

deecodameeko commented 10 years ago

Hey there,

I'm trying to use ng-jcrop on my website. I'm moving our front end to angular and found your directive solution for jcrop, which is cool. I'm having some issues though. I don't see any option to send trueSize through your directive and because of this am not getting the image coordinate ratio as expected. Is there something I'm missing? Is this something you're working on? If so I wouldn't mind contributing.

One thing I did try as a test was to hard code the original width and height of my test image into the js and that seemed to help but I'm still not getting what I chose to crop in my resulting image.

I have no problem extending your directive to take a trueSize but maybe there's something that's not quite clear to me.

Cheers,

D

andrefarzat commented 10 years ago

Hey, there,

I yet didn't implemented the ng-jcrop-config part which is like what you are in need. I was wondering in do something like this:

<div ng-jcrop="obj.src" ng-jcrop-config="obj.config" selection="obj.selection"></div>

and the obj.config would be the config object which goes in the $.Jcrop() call.

How was your implementation ? Mind showing it ? =)

Thank you

deecodameeko commented 10 years ago

I actually reverted to using Jcrop directly so I can't show you my implementation but I would like to help build your ng-jcrop if I could. I like your idea of having a config object to pass.

On Aug 22, 2014, at 6:40 PM, André Farzat notifications@github.com wrote:

Hey, there,

I yet didn't implemented the ng-jcrop-config part which is like what you are in need. I was wondering in do something like this:

and the obj.config would be the config object which goes in the $.Jcrop({}) call.

How was your implementation ? Mind showing it ? =)

Thank you

— Reply to this email directly or view it on GitHub.

andrefarzat commented 10 years ago

@deecodameeko if you're interested, you can implement it and make a pull request =) Is it ok ?

deecodameeko commented 10 years ago

Yes, I’ll try to start this week.

On Aug 24, 2014, at 2:19 PM, André Farzat notifications@github.com wrote:

@deecodameeko if you're interested, you can implement it and make a pull request =) Is it ok ?

— Reply to this email directly or view it on GitHub.

alexisohayon commented 9 years ago

Hi André, I would also be interested in a obj.config, which could be more flexible for the use of jCrop. Is it still planned ?

Thx!

andrefarzat commented 9 years ago

I was expecting it, but I may have time to implement it this Wednesday. Is it ok for you ?

alexisohayon commented 9 years ago

I made a work around directly with the jCrop lib by building my own directive, but I'll have a look on yours as soon as you implement it :) Let me know when it's pushed!

andrefarzat commented 9 years ago

@alexisohayon I added support using a ngJcropConfigProvider. Check out the last commits to see. I will update the README.md Tomorrow.

alexisohayon commented 9 years ago

Thanks! I'm gonna try this right away :) :+1:

alexisohayon commented 9 years ago

I'm reading your code, I see that I can set max width/height, but I don't see where to config the ratio / bgColor?

andrefarzat commented 9 years ago

You can use the ngJcropConfigProvider.setJcropConfig to set options direct to jcrop:

app.config(function(ngJcropConfigProvider){

    ngJcropConfigProvider.setJcropConfig({
        bgColor: 'black',
        bgOpacity: .4,
        aspectRatio: 16 / 9
    });

});

I updated the README.md with this example : https://github.com/andrefarzat/ng-jcrop/commit/602d25a0a8d94ac756850c89b322a328f4ba72fc

alexisohayon commented 9 years ago

Yeah this is really what I was looking for, but I'd like to set the config "on the go", dynamically when I call the directive. (I'm attaching it to a modal, which can have different kind of ratio depending on what service is calling it). Do you think that's possible?

2014-10-31 16:24 GMT+01:00 André Farzat notifications@github.com:

You can use the ngJcropConfigProvider.setJcropConfig to set options direct to jcrop:

app.config(function(ngJcropConfigProvider){

ngJcropConfigProvider.setJcropConfig({
    bgColor: 'black',
    bgOpacity: .4,
    aspectRatio: 16 / 9
});

});

I updated the README.md with this example : 602d25a https://github.com/andrefarzat/ng-jcrop/commit/602d25a0a8d94ac756850c89b322a328f4ba72fc

— Reply to this email directly or view it on GitHub https://github.com/andrefarzat/ng-jcrop/issues/2#issuecomment-61276754.

Alexis OHAYON, Co-founder @takes.io

www.takes.io - (+33) 6 66 85 14 21 Skype : alexis.ohayon

andrefarzat commented 9 years ago

I see. That's ok, it's possible. I gonna publish this as 1.0.3 and gonna start working in this change and publish it as 1.1.0 cause it might change the api through the directive.

alexisohayon commented 9 years ago

The config does'nt seem to be working with me :/

EDIT: I've looked into your code, and found this part : var config = angular.extend({ onChange: $scope.showPreview, onSelect: $scope.showPreview, aspectRatio: 1 }, ngJcropConfig);

It seems that this extend does'nt do the job, the aspectRatio stays at 1 no matter what (I tried to change bgColor too, not working either). Did you make a change to update the preview div (width & height) to fit the ratio too ? Tell me if you need help, I'll be happy to test with you :)

andrefarzat commented 9 years ago

@alexisohayon you're complete right ! I was passing the wrong config. This commit should fix it: https://github.com/andrefarzat/ng-jcrop/commit/7d807933aed1131d13da3367ee8ff178b428801c