From 92d3ec63ac3307c6e5445c20de130b42c33d2401 Mon Sep 17 00:00:00 2001 From: Nicolas Adenis-Lamarre Date: Mon, 21 Nov 2022 21:37:43 +0100 Subject: [PATCH] add gdimage output Signed-off-by: Nicolas Adenis-Lamarre --- qrconfig.php | 2 +- qrencode.php | 15 +++++++++++++++ qrimage.php | 6 ++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/qrconfig.php b/qrconfig.php index e53dff8..6f1d1f8 100644 --- a/qrconfig.php +++ b/qrconfig.php @@ -14,4 +14,4 @@ define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images - \ No newline at end of file + define('QR_GDIMAGE_MAXIMUM_SIZE', 1024); diff --git a/qrencode.php b/qrencode.php index 6c210e8..e202b6a 100644 --- a/qrencode.php +++ b/qrencode.php @@ -286,6 +286,13 @@ public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size return $enc->encodePNG($text, $outfile, $saveandprint=false); } + //---------------------------------------------------------------------- + public static function gdimage($text, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) + { + $enc = QRencode::factory($level, $size, $margin); + return $enc->encodeGDIMAGE($text); + } + //---------------------------------------------------------------------- public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) { @@ -566,4 +573,12 @@ public function encodeSVG($intext, $outfile = false,$saveandprint=false) } } + + //---------------------------------------------------------------------- + public function encodeGDIMAGE($intext) + { + $tab = $this->encode($intext); + $maxSize = (int)(QR_GDIMAGE_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); + return QRimage::gdimage($tab, min(max(1, $this->size), $maxSize), $this->margin); + } } diff --git a/qrimage.php b/qrimage.php index 48048e8..3a4bcc8 100644 --- a/qrimage.php +++ b/qrimage.php @@ -47,6 +47,12 @@ public static function png($frame, $filename = false, $pixelPerPoint = 4, $outer ImageDestroy($image); } + //---------------------------------------------------------------------- + public static function gdimage($frame, $pixelPerPoint = 4, $outerFrame = 4) + { + return self::image($frame, $pixelPerPoint, $outerFrame); + } + //---------------------------------------------------------------------- public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) {