diff --git a/index.php b/index.php index 9d35407..709ef01 100755 --- a/index.php +++ b/index.php @@ -38,7 +38,7 @@ $params = array( "fgColor" => DEFAULT_FGCOLOR, ); -$validFormSubmitted = false; +$qrCodeAvailable = NULL; if ( isset($_POST['txt']) @@ -49,6 +49,8 @@ if ( AND isset($_POST['fgColor']) ) { + $qrCodeAvailable = true; + if (strlen($_POST['txt']) >= 1 AND strlen($_POST['txt']) <= 4096) { $params['txt'] = $_POST['txt']; } else { @@ -96,6 +98,48 @@ if ( } $validFormSubmitted = true; + + $rgbBgColor = array( + 'r' => hexdec(substr($params['bgColor'],0,2)), + 'g' => hexdec(substr($params['bgColor'],2,2)), + 'b' => hexdec(substr($params['bgColor'],4,2)), + ); + + $qrCode = Builder::create() + ->data($params['txt']); + if (!is_null($params['margin'])) + $qrCode->margin($params['margin']); + if (!is_null($params['size'])) + $qrCode->size($params['size']); + + if ($params['redundancy'] === "high") + $qrCode->errorCorrectionLevel(new ErrorCorrectionLevelHigh()); + else if ($params['redundancy'] === "quartile") + $qrCode->errorCorrectionLevel(new ErrorCorrectionLevelQuartile()); + else if ($params['redundancy'] === "medium") + $qrCode->errorCorrectionLevel(new ErrorCorrectionLevelMedium()); + else if ($params['redundancy'] === "low") + $qrCode->errorCorrectionLevel(new ErrorCorrectionLevelLow()); + + $qrCode + ->backgroundColor(new Color( + $rgbBgColor['r'], + $rgbBgColor['g'], + $rgbBgColor['b'] + )) + ->foregroundColor(new Color( + hexdec(substr($params['fgColor'],0,2)), + hexdec(substr($params['fgColor'],2,2)), + hexdec(substr($params['fgColor'],4,2)) + )); + + try { + $result = $qrCode->build(); + } catch (Exception $ex) { + http_response_code(500); + $qrCodeAvailable = false; + error_log("LibreQR encountered an error while generating a QR code: " . $ex); + } } ?> @@ -205,64 +249,20 @@ foreach($themeDimensionsIcons as $dimFav) // Set all icons dimensions hexdec(substr($params['bgColor'],0,2)), - 'g' => hexdec(substr($params['bgColor'],2,2)), - 'b' => hexdec(substr($params['bgColor'],4,2)), - ); - - $qrCode = Builder::create() - ->data($params['txt']); - if (!is_null($params['margin'])) - $qrCode->margin($params['margin']); - if (!is_null($params['size'])) - $qrCode->size($params['size']); - - if ($params['redundancy'] === "high") - $qrCode->errorCorrectionLevel(new ErrorCorrectionLevelHigh()); - else if ($params['redundancy'] === "quartile") - $qrCode->errorCorrectionLevel(new ErrorCorrectionLevelQuartile()); - else if ($params['redundancy'] === "medium") - $qrCode->errorCorrectionLevel(new ErrorCorrectionLevelMedium()); - else if ($params['redundancy'] === "low") - $qrCode->errorCorrectionLevel(new ErrorCorrectionLevelLow()); - - $qrCode - ->backgroundColor(new Color( - $rgbBgColor['r'], - $rgbBgColor['g'], - $rgbBgColor['b'] - )) - ->foregroundColor(new Color( - hexdec(substr($params['fgColor'],0,2)), - hexdec(substr($params['fgColor'],2,2)), - hexdec(substr($params['fgColor'],4,2)) - )); - - try { - $result = $qrCode->build(); - } catch (Exception $ex) { - http_response_code(500); - echo "
" . $loc['error_generation'] . "