Code Monkey home page Code Monkey logo

Comments (20)

danielrhodeswarp avatar danielrhodeswarp commented on May 28, 2024

Oh dear, the formatting didn't go to plan! Obviously the jcropOptions are inside the Jcrop constructor as applied to the image object in question. Thanks.

from jcrop.

danielrhodeswarp avatar danielrhodeswarp commented on May 28, 2024

"The src is loaded into the" --> "The src is loaded into the image and draws correctly"

:-/

from jcrop.

danielrhodeswarp avatar danielrhodeswarp commented on May 28, 2024

I see from viewing the generated HTML source in Chrome, that how Jcrop works on an image is that the original image is made "display:none; visibility:hidden" and that a different image tag with the same src is made (nested in a div with class="jcrop-tracker") with "display:block; visibility:visible;" for the cropping magic to operate on.

I wonder if it something to with this? For example, Chrome fails to cache the image and reloads it again when Jcrop assigns the src to the new, generated image?

I am working on a separate testbed page to show you all but unfortunately I haven't been able to replicate the error outside of the current usage :-(

from jcrop.

sunchuo avatar sunchuo commented on May 28, 2024

i met the same problem :-(

------------update--------------------

i found a method in jquery.crop.js.

setImage(src, callback)

this method can change crop box image in live . but the image src didnt change . must use $.attr() .

from jcrop.

danielrhodeswarp avatar danielrhodeswarp commented on May 28, 2024

Thanks for the confirmation Sunchuo. I'm going to have a look at jquery.crop.js and see what I can find. I wonder if you have you been able to fix (or change?) this behaviour?

from jcrop.

danielrhodeswarp avatar danielrhodeswarp commented on May 28, 2024

Just out of interest Sunchou, I wonder if - like me - you are playing with Ajax when using Jcrop. I am requesting the image for cropping from a different server using cross domain Ajax.

from jcrop.

danielrhodeswarp avatar danielrhodeswarp commented on May 28, 2024

Ok, it looks like it's a Chrome problem: http://bugs.jquery.com/ticket/11075

from jcrop.

danielrhodeswarp avatar danielrhodeswarp commented on May 28, 2024

Aaaa, OK, I have managed to solve this issue by adding HTTP headers for caching (Cache-Control:max-age=xyz, Expires:Tue, some date) to my image server which returns the images that Jcrop operates on. (Luckily I am in control of the image server in this case!)

from jcrop.

jcart avatar jcart commented on May 28, 2024

I don't think this is desired behavior to have the resource loaded twice, reguardless whether it is cached for HTTP requests. Consider you are working with FileReader, and applying jCrop to prior to uploading. The load times for Blob elements can be relatively long while the browser it loading it into memory (especially for large files -- duh). At least with FileReader, we have an opportunity to track the loading of the image. Now, we have to track both the FileReader loading, as well as jCrop (which does not natively provide you callbacks to know when the image was finally initialized).

Not to mention there is sometimes an undesirable "flicker" when hiding the original to show the newly created "jcrop" image.

Please consider changing this behavior.

from jcrop.

danielrhodeswarp avatar danielrhodeswarp commented on May 28, 2024

But I don't think Jcrop itself can or should control the host browser's DOM / HTTP implementation.

I'm happy (and, OK, it's not up to me because I'm not a Jcrop developer!) that this isn't a Jcrop issue and is rather a Chrome-caching-when-using-dom-slash-ajax type of issue.

The flicker thing you mention sounds more like a Jcrop issue that should get fixed. Though I haven't experienced that myself so I can't really comment.

from jcrop.

danielrhodeswarp avatar danielrhodeswarp commented on May 28, 2024

Oh, sorry, you mean for Jcrop not to duplicate the (and its src) in the first place don't you? Yeah that would be super cool :-)

from jcrop.

danielrhodeswarp avatar danielrhodeswarp commented on May 28, 2024

the (and its src) --> the IMG (and its src)

from jcrop.

jcart avatar jcart commented on May 28, 2024
Oh, sorry, you mean for Jcrop not to duplicate the (and its src) in the first place don't you? Yeah that would be super cool :-)

This was what I meant, indeed.

from jcrop.

wedamir avatar wedamir commented on May 28, 2024

Hi guys, you can solve this problem by using
$(window).load(function(){
.....
});
insted of $(document).ready(function(){
.....
});

from jcrop.

danielrhodeswarp avatar danielrhodeswarp commented on May 28, 2024

Interesting! But do we know why that solves the issue?

from jcrop.

majuansari avatar majuansari commented on May 28, 2024

any solution for this issue ?

from jcrop.

danielrhodeswarp avatar danielrhodeswarp commented on May 28, 2024

Hi majuansari. I was able to mostly solve this issue by adding HTTP "expires" headers to the images in question - please see my comment about this above for more details.

from jcrop.

irineujunior avatar irineujunior commented on May 28, 2024

@danielrhodeswarp I fixed this issue converting blob file to base64

        var reader = new window.FileReader();
        reader.readAsDataURL(file);
        reader.onloadend = function() {
            base64data = reader.result;
            $('#jcrop_target_' + previewId).attr('src', base64data).Jcrop({
                aspectRatio: 4/3
            });
        }

Check the full code

$(".filestyle")
    .fileinput()
    .on('fileloaded', function(event, file, previewId, index, reader) {
        bootbox.dialog({
            title: 'Ajustar imagem',
            message: '<img src="" id="jcrop_target_' + previewId + '" class="img-responsive" />',
            buttons: {
                success: {
                    label: "Salvar",
                    className: "btn-flat btn-primary",
                    callback: function () {
                        console.log('Sucesso!')
                    }
                }
            }
        });

        var reader = new window.FileReader();
        reader.readAsDataURL(file);
        reader.onloadend = function() {
            base64data = reader.result;
            $('#jcrop_target_' + previewId).attr('src', base64data).Jcrop({
                aspectRatio: 4/3
            });
        }
    });

from jcrop.

Subhajyoti avatar Subhajyoti commented on May 28, 2024

I am using input type="file" id="uploadProfilePic" to fetch image from system. and put that image in
img id="uploadedImage" style="width: 100%; display: none" src="
and onload of this image cropp called. but without cropping and save if open another image the image is not refreshed. previous image is hold by 'jcrop-holder' class. How can i reload or refresh the new image??

from jcrop.

bil80 avatar bil80 commented on May 28, 2024

I solved the issue of black screen when reload by adding again the lines below in my DIV

<input type="hidden" id="x" name="x" />
 <input type="hidden" id="y" name="y" />
 <input type="hidden" id="w" name="w" />
 <input type="hidden" id="h" name="h" />
 <input type="submit" value="Crop Image" class="btn btn-large btn-inverse" />

from jcrop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.