Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add listener function that is triggered when picture is done moving / zooming #3

Closed
vlatka-sinisa opened this issue Sep 4, 2014 · 5 comments

Comments

@vlatka-sinisa
Copy link

I'm using your cropper as part of form in which user upload the image. Now I'm doing workaround so that when form is submitted the data is retrieved using the getData. Is it possible to define listener function so that my function would be triggered after the image is zoomed or moved (repositioned/cropped)?

@scottcheng
Copy link
Owner

Do you mean adding a callback as an option which gets called every time the image is zoomed/moved?

@vlatka-sinisa
Copy link
Author

Sorry for to little information.

as callback that would be called after the moving/zooming process is done. If possible not during the dragging/zooming since I guess the export every pixel zoomed/moved can slow the browser :)

@scottcheng
Copy link
Owner

Interesting. If I understand it correctly you want to be able to include the cropped image data in a form submission. If I were you I would probably try the following approach: bind a .submit jquery listener to the form, in which you read the cropped image data using .cropit('export'), and assign that image data to a hidden input, which will go with the form submission. Do you think that would work?

@vlatka-sinisa
Copy link
Author

Yes, perfect! I've tested it and it works just as expected!

@vlatka-sinisa
Copy link
Author

Sure,

this is the what we’ve done:

var imageCropper = $('#image-cropper');
imageCropper.closest("form").submit(function(){
var imageCropper = $('#{$tuniq}-image-cropper');
var image = imageCropper.cropit('export', {
type: 'image/png',
originalSize: false
});

imageCropper.find(".cropit-image-data").val( image );
});

We’ve also needed one hidden field where the data is placed when its exported:
<input type="hidden" name=“image-data" class="cropit-image-data" />

(just add it inside the

// … other cropit options if needed ...

Sinisa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants