<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
//load the ar library
include 'phpqrcode/qrlib.php';

//data to be stored in qr
//$text = "pruebaljoi5joijoi4joi4joi5jo4ij5oijoi5jioj5oijoi5j4ioj";
$data = json_decode(file_get_contents("php://input"));
if(
    !empty($data->datos)
){
  
$ecc = 'H';
$pixel_size = 2.0;
$frame_size = 5;
ob_start();
QRcode::png($data->datos,null, $ecc, $pixel_size, $frame_size);
$imageString = base64_encode(ob_get_contents());
ob_end_clean();
echo json_encode(array("image64" =>$imageString));
//echo $imageString;

}else{

    http_response_code(400);
    echo json_encode(array("message" => "string vacio"));
} 

?>