Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JCrop in Firefox attaches original image height/width

Tags:

jquery

css

jcrop

We're using the JCrop library for cropping the profile picture. When the user changes his profile picture, the new picture still uses the old image dimensions. This works in Chrome but doesn't work in Firefox. I remove the previous image and the JCrop using the destroy:

jcrop_api.destroy();

I have also added this line of code in an attempt to clear the styles that contains the width and the height.

$('#target').removeAttr('style');
like image 843
Anshuman Biswas Avatar asked Nov 12 '22 22:11

Anshuman Biswas


1 Answers

I have also met this issue and I tried everything and finally discovered a workaround that works for me:

There must be an alert() function if using Firefox and jcrop destruction and initialization again.

// Clear selector
if (jcropAPI) {
    jcropAPI.destroy();
    }

initCropper();

// If browser is Firefox, fix bug with stretching
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
    // Do Firefox-related activities
    alert('File successfully loaded');  // this alert is necessary
    if (jcropAPI) {
        jcropAPI.destroy();
    }
    initCropper();
}
like image 107
OndrejC Avatar answered Nov 14 '22 22:11

OndrejC