summaryrefslogtreecommitdiff
path: root/vendor/chillerlan/php-qrcode/src/Output/QRImage.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/chillerlan/php-qrcode/src/Output/QRImage.php')
-rw-r--r--vendor/chillerlan/php-qrcode/src/Output/QRImage.php65
1 files changed, 37 insertions, 28 deletions
diff --git a/vendor/chillerlan/php-qrcode/src/Output/QRImage.php b/vendor/chillerlan/php-qrcode/src/Output/QRImage.php
index 598948c94..8f533d341 100644
--- a/vendor/chillerlan/php-qrcode/src/Output/QRImage.php
+++ b/vendor/chillerlan/php-qrcode/src/Output/QRImage.php
@@ -19,30 +19,36 @@ use chillerlan\QRCode\{QRCode, QRCodeException};
use chillerlan\Settings\SettingsContainerInterface;
use Exception;
-use function array_values, base64_encode, call_user_func, count, imagecolorallocate, imagecolortransparent,
+use function array_values, base64_encode, call_user_func, count, extension_loaded, imagecolorallocate, imagecolortransparent,
imagecreatetruecolor, imagedestroy, imagefilledrectangle, imagegif, imagejpeg, imagepng, in_array,
is_array, ob_end_clean, ob_get_contents, ob_start, range, sprintf;
/**
- * Converts the matrix into GD images, raw or base64 output
- * requires ext-gd
- * @link http://php.net/manual/book.image.php
+ * Converts the matrix into GD images, raw or base64 output (requires ext-gd)
+ *
+ * @see http://php.net/manual/book.image.php
*/
class QRImage extends QROutputAbstract{
+ /**
+ * GD image types that support transparency
+ *
+ * @var string[]
+ */
protected const TRANSPARENCY_TYPES = [
QRCode::OUTPUT_IMAGE_PNG,
QRCode::OUTPUT_IMAGE_GIF,
];
- /**
- * @var string
- */
- protected $defaultMode = QRCode::OUTPUT_IMAGE_PNG;
+ protected string $defaultMode = QRCode::OUTPUT_IMAGE_PNG;
/**
+ * The GD image resource
+ *
* @see imagecreatetruecolor()
- * @var resource
+ * @var resource|\GdImage
+ *
+ * @phan-suppress PhanUndeclaredTypeProperty
*/
protected $image;
@@ -84,15 +90,20 @@ class QRImage extends QROutputAbstract{
/**
* @inheritDoc
*
- * @return string|resource
+ * @return string|resource|\GdImage
+ *
+ * @phan-suppress PhanUndeclaredTypeReturnType, PhanTypeMismatchReturn
*/
public function dump(string $file = null){
+ $file ??= $this->options->cachefile;
+
$this->image = imagecreatetruecolor($this->length, $this->length);
// avoid: Indirect modification of overloaded property $imageTransparencyBG has no effect
// https://stackoverflow.com/a/10455217
- $tbg = $this->options->imageTransparencyBG;
- $background = imagecolorallocate($this->image, ...$tbg);
+ $tbg = $this->options->imageTransparencyBG;
+ /** @phan-suppress-next-line PhanParamTooFewInternalUnpack */
+ $background = imagecolorallocate($this->image, ...$tbg);
if((bool)$this->options->imageTransparent && in_array($this->options->outputType, $this::TRANSPARENCY_TYPES, true)){
imagecolortransparent($this->image, $background);
@@ -110,7 +121,11 @@ class QRImage extends QROutputAbstract{
return $this->image;
}
- $imageData = $this->dumpImage($file);
+ $imageData = $this->dumpImage();
+
+ if($file !== null){
+ $this->saveToFile($imageData, $file);
+ }
if($this->options->imageBase64){
$imageData = sprintf('data:image/%s;base64,%s', $this->options->outputType, base64_encode($imageData));
@@ -120,11 +135,7 @@ class QRImage extends QROutputAbstract{
}
/**
- * @param int $x
- * @param int $y
- * @param array $rgb
- *
- * @return void
+ * Creates a single QR pixel with the given settings
*/
protected function setPixel(int $x, int $y, array $rgb):void{
imagefilledrectangle(
@@ -133,20 +144,17 @@ class QRImage extends QROutputAbstract{
$y * $this->scale,
($x + 1) * $this->scale,
($y + 1) * $this->scale,
+ /** @phan-suppress-next-line PhanParamTooFewInternalUnpack */
imagecolorallocate($this->image, ...$rgb)
);
}
/**
- * @param string|null $file
+ * Creates the final image by calling the desired GD output function
*
- * @return string
-
* @throws \chillerlan\QRCode\Output\QRCodeOutputException
*/
- protected function dumpImage(string $file = null):string{
- $file = $file ?? $this->options->cachefile;
-
+ protected function dumpImage():string{
ob_start();
try{
@@ -164,14 +172,12 @@ class QRImage extends QROutputAbstract{
ob_end_clean();
- if($file !== null){
- $this->saveToFile($imageData, $file);
- }
-
return $imageData;
}
/**
+ * PNG output
+ *
* @return void
*/
protected function png():void{
@@ -186,6 +192,7 @@ class QRImage extends QROutputAbstract{
/**
* Jiff - like... JitHub!
+ *
* @return void
*/
protected function gif():void{
@@ -193,6 +200,8 @@ class QRImage extends QROutputAbstract{
}
/**
+ * JPG output
+ *
* @return void
*/
protected function jpg():void{