25
25
* Converts the matrix into GD images, raw or base64 output (requires ext-gd)
26
26
*
27
27
* @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
28
32
*/
29
33
class QRGdImage extends QROutputAbstract{
30
34
@@ -33,6 +37,8 @@ class QRGdImage extends QROutputAbstract{
33
37
*
34
38
* @see imagecreatetruecolor()
35
39
* @var resource|\GdImage
40
+ *
41
+ * @todo: add \GdImage type in v6
36
42
*/
37
43
protected $ image ;
38
44
@@ -209,6 +215,7 @@ public function dump(string $file = null){
209
215
$ this ->saveToFile ($ imageData , $ file );
210
216
211
217
if ($ this ->options ->outputBase64 ){
218
+ // @todo: remove mime parameter in v6
212
219
$ imageData = $ this ->toBase64DataURI ($ imageData , 'image/ ' .$ this ->options ->outputType );
213
220
}
214
221
@@ -261,6 +268,7 @@ protected function setBgColor():void{
261
268
*/
262
269
protected function setTransparencyColor ():void {
263
270
271
+ // @todo: the jpg skip can be removed in v6
264
272
if ($ this ->options ->outputType === QROutputInterface::GDIMAGE_JPG || !$ this ->options ->imageTransparent ){
265
273
return ;
266
274
}
@@ -319,36 +327,55 @@ protected function module(int $x, int $y, int $M_TYPE):void{
319
327
);
320
328
}
321
329
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
+
322
366
/**
323
367
* Creates the final image by calling the desired GD output function
324
368
*
325
369
* @throws \chillerlan\QRCode\Output\QRCodeOutputException
326
370
*/
327
371
protected function dumpImage ():string {
328
372
$ exception = null ;
373
+ $ imageData = null ;
329
374
330
375
ob_start ();
331
376
332
377
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 ();
352
379
353
380
$ imageData = ob_get_contents ();
354
381
imagedestroy ($ this ->image );
0 commit comments