Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
html2canvas javascript screenshot pass to python

would it be possible to use html2canvas to take a picture of the user`s screen but also i wanna use this image with python function. What I want to do is save the image of the html element with javascript and send it to slack with python.

 function capture() {
          html2canvas(document.getElementById("main"), {
              letterRendering: 1,
              allowTaint: true,
              useCORS: true,
          })
              .then(function (canvas) {
                  document.getElementById("result").src = canvas.toDataURL("image/png", 0.5);
              })
              .catch((e) => {
                  alert(e);
              });
      }
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can use the HTMLCanvasElement.toBlob function to convert the canvas image into a Blob that you can send through fetch.

.then(function (canvas) {
  canvas.toBlob(blob => {
    fetch("URL", {
      method: 'POST',
      headers: { 'Content-Type': 'image/png' }
      body: blob
    })
  
    const imgSrc = URL.createObjectURL(blob);
    document.getElementById("result").onload = () => URL.revokeObjectURL(imgSrc);
    document.getElementById("result").src = imgSrc;
  }, "image/png", 0.5)
});
about 4 years ago · Santiago Trujillo Denunciar

0

i resolved problem like that;

JS;

<script>
      function capture() {
          html2canvas(document.getElementById("main"), {
              letterRendering: 1,
              allowTaint: true,
              useCORS: true,
          })
              .then(function (canvas) {
                  document.getElementById("result").src = canvas.toDataURL("image/png", 0.5);
                  var img = canvas.toDataURL();
                  $.ajax({
                  type: "POST",
                  url: "{% url 'sendtoslack' %}",
                  data: { 
                  "imageData": img,
                  csrfmiddlewaretoken: '{{ csrf_token }}'
                  }
                  
              })
              })
              .catch((e) => {
                  alert(e);
              });
      }
  </script>

view;

image = request.POST.get('imageData')

decoding base64;

import base64

imagestr = str(image)
x = imagestr[22:]
img = Image.open(io.BytesIO(base64.decodebytes(bytes(x, "utf-8"))))
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda