javascript - Convert base 64 encoding string into image -


i want convert base 64 encoding image png or jpeg image.

i want convert image , must save on server, must move in other folder can fetch it. have given here code save.php

<?php header('content-type: image/png'); header('content-disposition: attachment; filename="' . $_post['name'] .'"');  echo '<img src="'.$_post['img_val'].'" />';  $filtereddata=substr($_post['img_val'], strpos($_post['img_val'], ",")+1); $unencodeddata=base64_decode($filtereddata);   $return=file_put_contents('img.png', $unencodeddata);  ?> 

this javascript function sending data save.php

function capture(){ html2canvas($("#share"), {     onrendered: function(canvas) {         var myimage = canvas.todataurl("image/png");         $('#img_val').val(myimage);   document.getelementbyid("myform").submit();     } }); 

looks right, however, think you're missing there's garbage characters you're going need strip out javascript canvas.todataurl() call, namely spaces, you'll have convert plus-signs. otherwise corrupt data, example:

<?php   $encodeddata = str_replace(' ','+',$encodeddata);   $decoceddata = base64_decode($encodeddata); ?> 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -