0
Hello, I’m trying to finish a part of a system, where the user draws his signature and after the action, the Canvas Image is sent to the directory, but when I open the Saved image appears the following error: The image "https://br918.hostgator.com.br:2083/cpsess0222983772/view/home1%2fdsenv18%2pagina.life%2TESTE%2fpagina%2fimg/signature.png" Cannot be displayed bacause it contains error.
Could one of you help me?
PHP
$data = substr($_POST['imageData'], strpos($_POST['imageData'], ",") + 1);
$decodedData = base64_decode($data);
$fp = fopen("img/assinatura.png", 'wb');
fwrite($fp, $decodedData);
fclose($fp);
JAVASCRIPT
<script>
function salvarImagem(a){
var meucanvas = document.getElementById('newSignature');
var arquivo = document.getElementById('arquivo');
/*Comentário: a variavel "a" será o nome do arquivo, use aspas para chamar a função */
arquivo.download = a;
arquivo.href = meucanvas.toDataURL();
function signatureSave(url, name, fn, canvas, type) {
var data = document.getElementById("assinatura.png").toDataURL();
$.post("assinatura.png", {
imageData : data
}, function(data) {
alert('imagem salva');
});
}
meucanvas.toDataURL("image/png"). replace("image/png", "image/octet-stream");
– Augusto Vasques
Where is
arquivo.href = meucanvas.toDataURL();
doarquivo.href =meucanvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
– Augusto Vasques
Thanks for the comment Augusto, I changed the line of code DE: file.href = meucanvas.toDataURL(); POR: file.href = meucanvas.toDataURL("image/png"). replace("image/png", "image/octet-stream"); :(
– Davi
Too bad, I’ll do more research if I find something to help you.
– Augusto Vasques
Thanks for the help Augusto, I’ll keep trying to solve, thanks for your time.
– Davi