2525 * Converts the matrix into GD images, raw or base64 output (requires ext-gd)
2626 *
2727 * @see https://php.net/manual/book.image.php
28+ *
29+ * @deprecated 5.0.0 this class will be made abstract in future versions,
30+ * calling it directly is deprecated - use one of the child classes instead
31+ * @see https://github.com/chillerlan/php-qrcode/issues/223
2832 */
2933class QRGdImage extends QROutputAbstract{
3034
@@ -33,6 +37,8 @@ class QRGdImage extends QROutputAbstract{
3337 *
3438 * @see imagecreatetruecolor()
3539 * @var resource|\GdImage
40+ *
41+ * @todo: add \GdImage type in v6
3642 */
3743 protected $ image ;
3844
@@ -209,6 +215,7 @@ public function dump(string $file = null){
209215 $ this ->saveToFile ($ imageData , $ file );
210216
211217 if ($ this ->options ->outputBase64 ){
218+ // @todo: remove mime parameter in v6
212219 $ imageData = $ this ->toBase64DataURI ($ imageData , 'image/ ' .$ this ->options ->outputType );
213220 }
214221
@@ -261,6 +268,7 @@ protected function setBgColor():void{
261268 */
262269 protected function setTransparencyColor ():void {
263270
271+ // @todo: the jpg skip can be removed in v6
264272 if ($ this ->options ->outputType === QROutputInterface::GDIMAGE_JPG || !$ this ->options ->imageTransparent ){
265273 return ;
266274 }
@@ -319,36 +327,55 @@ protected function module(int $x, int $y, int $M_TYPE):void{
319327 );
320328 }
321329
330+ /**
331+ * Renders the image with the gdimage function for the desired output
332+ *
333+ * @see \imagebmp()
334+ * @see \imagegif()
335+ * @see \imagejpeg()
336+ * @see \imagepng()
337+ * @see \imagewebp()
338+ *
339+ * @todo: v6.0: make abstract and call from child classes
340+ * @see https://github.com/chillerlan/php-qrcode/issues/223
341+ * @codeCoverageIgnore
342+ */
343+ protected function renderImage ():void {
344+
345+ switch ($ this ->options ->outputType ){
346+ case QROutputInterface::GDIMAGE_BMP :
347+ imagebmp ($ this ->image , null , ($ this ->options ->quality > 0 ));
348+ break ;
349+ case QROutputInterface::GDIMAGE_GIF :
350+ imagegif ($ this ->image );
351+ break ;
352+ case QROutputInterface::GDIMAGE_JPG :
353+ imagejpeg ($ this ->image , null , max (-1 , min (100 , $ this ->options ->quality )));
354+ break ;
355+ case QROutputInterface::GDIMAGE_WEBP :
356+ imagewebp ($ this ->image , null , max (-1 , min (100 , $ this ->options ->quality )));
357+ break ;
358+ // silently default to png output
359+ case QROutputInterface::GDIMAGE_PNG :
360+ default :
361+ imagepng ($ this ->image , null , max (-1 , min (9 , $ this ->options ->quality )));
362+ }
363+
364+ }
365+
322366 /**
323367 * Creates the final image by calling the desired GD output function
324368 *
325369 * @throws \chillerlan\QRCode\Output\QRCodeOutputException
326370 */
327371 protected function dumpImage ():string {
328372 $ exception = null ;
373+ $ imageData = null ;
329374
330375 ob_start ();
331376
332377 try {
333-
334- switch ($ this ->options ->outputType ){
335- case QROutputInterface::GDIMAGE_BMP :
336- imagebmp ($ this ->image , null , ($ this ->options ->quality > 0 ));
337- break ;
338- case QROutputInterface::GDIMAGE_GIF :
339- imagegif ($ this ->image );
340- break ;
341- case QROutputInterface::GDIMAGE_JPG :
342- imagejpeg ($ this ->image , null , max (-1 , min (100 , $ this ->options ->quality )));
343- break ;
344- case QROutputInterface::GDIMAGE_WEBP :
345- imagewebp ($ this ->image , null , max (-1 , min (100 , $ this ->options ->quality )));
346- break ;
347- // silently default to png output
348- case QROutputInterface::GDIMAGE_PNG :
349- default :
350- imagepng ($ this ->image , null , max (-1 , min (9 , $ this ->options ->quality )));
351- }
378+ $ this ->renderImage ();
352379
353380 $ imageData = ob_get_contents ();
354381 imagedestroy ($ this ->image );
0 commit comments