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
JCrop attaches height and width to the original image tag, but doesn't remove them upon destruction #46
Comments
+1 The workaround only works for very simple cases / img elements - any number of other properties (e.g. unique IDs, CSS classes, data attributes, etc) could be destroyed. IMHO jCrop shouldn't need to modify the image at all, it should store the height & width using jQuery data(), which will in turn use data- attributes when available, and otherwise use jQuery's internal data storage system. These values should also be automatically removed during destroy(). |
+1 Add 'visibility' to this list |
Yep just hit this issue. Is there a robust work around for this? |
I doubt this could be classified as "robust", but this has been working for me:
|
That is working for me too |
yes, this worked fine. and as per my analysis it is the workaround needed. |
I'm running up against this too. I had used setImage previously, but for some reason that's not working for me anymore. |
+1 |
1 similar comment
+1 |
I'm removing the style attribute too. I don't know why jCrop wouldn't return the DOM as it was before. |
I'm signing in just to up this comment: tomatohater commented 9 months ago
I doubt this could be classified as "robust", but this has been working for me:
jcrop_api.destroy();
$('.imagePreviewLarge').removeAttr('style'); And many thanks to the topic creator. zx |
+1, removeAttr is old school but it works. |
This (the removeAttr("style");) worked for me as well. BUT, only on Chrome. |
My original suggestion, to remove the tag from the DOM and add it again, although not ideal, was working in Firefox. It is not as clean as some of the other solutions though. |
@talofo My recent tests show that the destroy/removeAttr method does work in Chrome/FF/Safari/IE11. Are you sure nothing else is bombing out? I whipped up a barebones example that compares the default behavior with the removeAttr workaround: http://jcrop-issue-46.herokuapp.com/ I do believe that this cleanup would be better off in the .destroy() method itself. But until then... |
No dice. :( It's so frustrating. I have all a crop php plugin based on this, and it keeps showing two images with visibility: visible, instead of one, and it keeps putting the second image with the wrong withs and heights. I'm completely lost on all this code already, with no clear way to solve this. |
It is really frustrating. Took a long way to understand what was happening, Tried to fix, but no use. Please let me know when this issue will be fixed. |
work for me jQuery(function($) {
function showCoords(c) {
// variables can be accessed here as
// c.x, c.y, c.x2, c.y2, c.w, c.h
};
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
//remove current jcrop
$('.jcrop-holder').replaceWith('');
//replace with new image
$('#avatar-crop').replaceWith('<img id="avatar-crop" src="' + e.target.result + '" width="100%"/>');
//run jcrop again
$("#avatar-crop").Jcrop({
onSelect: showCoords,
onChange: showCoords
});
}
reader.readAsDataURL(input.files[0]);
}
}
// first run jcrop
$("#avatar-crop").Jcrop({
onSelect: showCoords,
onChange: showCoords
});
//input file
$("#user_avatar").change(function() {
readURL(this);
});
}); tested: jquery.Jcrop.js v0.9.12 |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
I've given up on Jcrop and am switching to using Cropper instead - play with the demo, it's fantastic! |
+1, p.s. @MarcusJT thanks for the link |
Unfortunately Cropper is a disaster on cell phones (running Opera or Chrome) and pans the image instead of the cropping area when using the cursor keys on a PC (running Opera or Chrome). I found that Jcrop has much better compatibility. |
Strange, CropperJS works perfectly for me in Chrome on Android, I just tried it. As for cursor keys panning the image rather than the cropping area, that's an implementation decision which surely you could either fork and change, or there may even be a fully supported way to change this (i.e. by configuring something or writing a little code to override the default keypress event handler) Anyway, I've not needed to crop images since I last posted and I'm unlikely to again, so I'm going to bow out of & unsubscribe from this thread, all the best! |
Hello Folks, I had to develop an application using a Webcam as well as Upload File along with JCrop - that with toggle options between Cam and the Upload File. What worked for me was to reset the canvas height and width while Cropping the image - see $('#btnCrop').click Here is the entire code:
|
MOVED FROM GOOGLE CODE
What steps will reproduce the problem?
What is the expected output? What do you see instead?
You'll see that the image is now stretched to the dimensions of the previous image.
What version of the product are you using? On what operating system?
0.9.9
Please provide any additional information below.
The reason this happens is because when JCrop is first initialized, it attaches height and width attributes to the tag that you initialize it with. However, after calling destroy(), the height and width attributes are still present, so you can't just update the source and open JCrop again. The fix would be to remove the height and width attributes (or reset them to their original values) in the destroy() method.
The text was updated successfully, but these errors were encountered: