for a big school project, i need to build a custom uploader media button (it’s done), but i also need (really need) to allow cropping on image that are uploaded by users, like you can see when you upload a new logo on wordpress theme in site identity section.

I’m searching since few days without find any solution, I really hope you will help me. Thanks ! :)

the script that i use to display the custom media uploader is here :

(function ($){

$("#addmedia").click(function(e){
    e.preventDefault();
    var uploader = wp.media({
        title : 'Choisir une image de profil',
        button : {
            text : 'Valider !',
        },
        multiple : false,


    })

    .on('select', function(){
        var selection = uploader.state().get('selection');
        var attachement = selection.first().toJSON();
        var picture = attachement.url;
        $("#pic_val").attr("src", picture );
        $("#user_pic").val(picture);
    })

    .open();
})

$("#addlogo").click(function(e){
    e.preventDefault();
    var uploader = wp.media({
        title : 'Choisir un logo pour votre entreprise',
        button : {
            text : 'Valider',
        },
        multiple : false,


    })

    .on('select', function(){
        var selection = uploader.state().get('selection');
        var attachement = selection.first().toJSON();
        var picture = attachement.url;
        $("#pic_ent_val").attr("src", picture );
        $("#ent_pic").val(picture);
    })

    .open();
}); })(jQuery);

Read more here: WordPress media uploader cropping


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: