andyvr/picEdit

defaultImage as dataurl

Closed this issue · 3 comments

Can a dataurl be used as defaultImage and be set runtime?

You can add an URL (from the same server to prevent CORS issues) to the defaultImage option such as:

defaultImage: "my/custom/same/server/url"

If you want to change it while runtime, I believe you will have to delete the picEdit element and create it again with Javascript.

However, I believe there is an issue with "defaultImage" option of picEdit plugin.
I found performance troubles using it like that.
It seems that part of the _create_image_with_datasrc JS function from the plugin code is executed infinite times. Specifically the img.onload function (line 421 of the picEdit.js file).

In order to solve the problem, I changed lines 421-437 (surrounding the img.onload function) on my own picEdit JS file with the following code:

$(img).one("load", function() {
    if(dataurl) {
        var canvas = document.createElement('canvas');
        var ctx = canvas.getContext('2d');
        canvas.width = img.width;
        canvas.height = img.height;
        ctx.drawImage(img, 0, 0);
        img.src = canvas.toDataURL('image/png');
    }
    _this._image = img;
    _this._resizeViewport();
    _this._paintCanvas();
    _this.options.imageUpdated(_this._image);
    _this._mainbuttons.removeClass("active");
    if(callback && typeof(callback) == "function") callback();
});

So maybe you can do the same with your picedit.js file.

Hey Guys , i just want to load the defult image with window.img_src variable but it seems the picedit image defaultImage setting initialized befoer getting any change that i place a cpode to window.img_src varaible how could i change the degault image after loaded please ?

You can try to set the default image directly with the plugin, like so:
$('#image').picEdit("set_default_image","//www.gravatar.com/avatar/00000000000000000000000000000000?s=500")