Search code examples
jsonajaxcodeigniterqr-codecodeigniter-4

How to return qr code as image png to ajax in CI 4


Currently i'm using class from https://github.com/endroid/qr-code and i have return $qrCode->writeString() from controller as json_encode to AJAX. But the qr code result is not image. Is it possible to make qr code result as image(png) without save the image ? Thank you


Solution

  • I solve it with below code :

    Controller :

    $qrCode->setWriterByExtension('png'); //change it to png
    

    return value to AJAX with $qrCode->writeDataUri() not $qrCode->writeString()

    and parse the value into img src attr