This is a migrated thread and some comments may be shown as answers.

Base64 of the edited image

3 Answers 705 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
Rogerio
Top achievements
Rank 1
Rogerio asked on 11 Apr 2021, 12:38 AM

how to get base64 from the edited image, any sample or documentation?

 

tks

3 Answers, 1 is accepted

Sort by
0
Accepted
Stoyan
Telerik team
answered on 14 Apr 2021, 03:02 PM

Hello Rogerio,
Thank you for your question.

To get the base64 of an image you have already edited use the getCurrentImage() method. This Dojo sample showcases the behavior. In it import a new image to get its base64 in the browser's console.

Alternatively, you can use the getCanvasElement method and then apply the HTMLCanvasElement.toDataURL() to it. Review this approach here.

Hopefully the above helps.

Regards,
Stoyan
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

0
Rogerio
Top achievements
Rank 1
answered on 17 Apr 2021, 10:16 PM

Thank you, it worked with your tips, I did it like this with PHP:

 

JS:

 
       var imageEditor = $("#imageEditor").getKendoImageEditor();
        var canvas = imageEditor.getCanvasElement();
        var image = canvas.toDataURL();
 
            $.ajax({
            url:"saveimageeditor.php",
            // send the base64 post parameter
            data:{
                filename: '<?php echo $filelo; ?>',
                base64: image
            },
            // important POST method !
            type:"post",
            complete:function(){
                console.log("Image saved successfully!");
            }

 

PHP :

// baseFromJavascript will be the javascript base64 string retrieved of some way (async or post submited)
 
//your data in base64 'data:image/png....'
$baseFromJavascript = $_POST['base64']; 
 
// We need to remove the "data:image/png;base64,"
$base_to_php = explode(',', $baseFromJavascript);
 
// the 2nd item in the base_to_php array contains the content of the image
$data = base64_decode($base_to_php[1]);
 
$filepath = $_POST['filename'];
 
// Save the image
file_put_contents($filepath,$data);

 

 

0
Stoyan
Telerik team
answered on 19 Apr 2021, 02:48 PM

Hi Rogerio,

I am glad the suggested solution worked. Thank you for sharing you code, I'm sure it will be useful to our community.

Regards,
Stoyan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ImageEditor
Asked by
Rogerio
Top achievements
Rank 1
Answers by
Stoyan
Telerik team
Rogerio
Top achievements
Rank 1
Share this question
or