Skip to content

Instantly share code, notes, and snippets.

@grekodev
Created December 14, 2019 16:59
Show Gist options
  • Save grekodev/6842ee7644bbeed33217156ca6de6fe0 to your computer and use it in GitHub Desktop.
Save grekodev/6842ee7644bbeed33217156ca6de6fe0 to your computer and use it in GitHub Desktop.

Revisions

  1. grekodev renamed this gist Dec 14, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. grekodev created this gist Dec 14, 2019.
    28 changes: 28 additions & 0 deletions render_php_js_image.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    PHP
    =======
    public function readImage()
    {
    header('Content-type: image/jpeg');
    echo file_get_contents("http://app1.susalud.gob.pe/registro/Home/GeneraCaptcha?accion=image");
    }
    ===================================================================================================
    JS
    =======
    function getCaptcha(url_image) {
    fetch(url_image)
    .then(response => response.blob())
    .then(images => {
    var reader = new window.FileReader();
    reader.readAsDataURL(images);
    reader.onload = function () {
    var imageDataUrl = reader.result;
    let imageElement = document.getElementById('image');
    imageElement.setAttribute("src", imageDataUrl);
    }
    })
    }

    ===================================================================================================
    HTML
    =======
    <img id="image" alt="">