summaryrefslogtreecommitdiff
path: root/vendor/chillerlan/php-qrcode/src/Output/QRImage.php
diff options
context:
space:
mode:
authorChih-Hsuan Yen <[email protected]>2022-07-02 22:01:51 +0800
committerAndrew Dolgov <[email protected]>2022-07-12 22:23:48 +0300
commit4b6161892000cb2b8392dce92a9cf2cabdf2d20e (patch)
tree5cad602010e4d13e1a48d6b922d4768c0893ac8b /vendor/chillerlan/php-qrcode/src/Output/QRImage.php
parentd9861038bcc3cb2f38c7153bdca7d5ab89597afa (diff)
Update php-qrcode and php-settings-container for PHP 8.1
By running the following command after updating composer.json ``` composer update chillerlan/php-qrcode chillerlan/php-settings-container ``` This change fixes a deprecation warning from Preferences -> Personal data / Authentication -> Authenticator (OTP). ``` Return type of chillerlan\Settings\SettingsContainerAbstract::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice 1. vendor/chillerlan/php-settings-container/src/SettingsContainerAbstract.php(19): ttrss_error_handler(Return type of chillerlan\Settings\SettingsContainerAbstract::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice, vendor/chillerlan/php-settings-container/src/SettingsContainerAbstract.php) 2. vendor/composer/ClassLoader.php(571): include(/usr/share/webapps/tt-rss/vendor/chillerlan/php-settings-container/src/SettingsContainerAbstract.php) 3. vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile(/usr/share/webapps/tt-rss/vendor/composer/../chillerlan/php-settings-container/src/SettingsContainerAbstract.php) 4. vendor/chillerlan/php-qrcode/src/QROptions.php(59): loadClass(chillerlan\Settings\SettingsContainerAbstract) 5. vendor/composer/ClassLoader.php(571): include(/usr/share/webapps/tt-rss/vendor/chillerlan/php-qrcode/src/QROptions.php) 6. vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile(/usr/share/webapps/tt-rss/vendor/composer/../chillerlan/php-qrcode/src/QROptions.php) 7. vendor/chillerlan/php-qrcode/src/QRCode.php(113): loadClass(chillerlan\QRCode\QROptions) 8. classes/pref/prefs.php(958): __construct() 9. classes/pref/prefs.php(469): _get_otp_qrcode_img() 10. classes/pref/prefs.php(541): index_auth_2fa() 11. backend.php(136): index_auth() ``` The issue is fixed in php-settings-container 2.1.1 [1] Here I use the latest php-qrcode version for another PHP 8.1 fix [2]. [1] https://github.com/chillerlan/php-settings-container/commit/68bc5019c8b38956c83906431ef879668366b036#diff-359c7f7a6d32d9935951e1b0742eb116fb654f4a932c8d40328bb5dcab2fa111L162 [2] https://github.com/chillerlan/php-qrcode/issues/97
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{