PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.18
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.18
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / vendor_prefixed / chillerlan / php-qrcode / src / Common / GDLuminanceSource.php

GDLuminanceSource.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.18, at vendor_prefixed/chillerlan/php-qrcode/src/Common/GDLuminanceSource.php

83 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class GDLuminanceSource
5 *
6 * @created 17.01.2021
7 * @author Ashot Khanamiryan
8 * @author Smiley <smiley@chillerlan.net>
9 * @copyright 2021 Smiley
10 * @license MIT
11 *
12 * @noinspection PhpComposerExtensionStubsInspection
13 */
14 namespace WCPOS\Vendor\chillerlan\QRCode\Common;
15
16 use WCPOS\Vendor\chillerlan\QRCode\Decoder\QRCodeDecoderException;
17 use WCPOS\Vendor\chillerlan\Settings\SettingsContainerInterface;
18 use function file_get_contents, get_resource_type, imagecolorat, imagecolorsforindex, imagecreatefromstring, imagefilter, imagesx, imagesy, is_resource;
19 use const IMG_FILTER_BRIGHTNESS, IMG_FILTER_CONTRAST, IMG_FILTER_GRAYSCALE, IMG_FILTER_NEGATE, PHP_MAJOR_VERSION;
20 /**
21 * This class is used to help decode images from files which arrive as GD Resource
22 * It does not support rotation.
23 */
24 class GDLuminanceSource extends LuminanceSourceAbstract
25 {
26 /**
27 * @var resource|\GdImage
28 */
29 protected $gdImage;
30 /**
31 * GDLuminanceSource constructor.
32 *
33 * @param resource|\GdImage $gdImage
34 * @param \chillerlan\Settings\SettingsContainerInterface|null $options
35 *
36 * @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException
37 */
38 public function __construct($gdImage, ?SettingsContainerInterface $options = null)
39 {
40 /** @noinspection PhpFullyQualifiedNameUsageInspection */
41 if (PHP_MAJOR_VERSION >= 8 && !$gdImage instanceof \GdImage || PHP_MAJOR_VERSION < 8 && (!is_resource($gdImage) || get_resource_type($gdImage) !== 'gd')) {
42 throw new QRCodeDecoderException('Invalid GD image source.');
43 // @codeCoverageIgnore
44 }
45 parent::__construct(imagesx($gdImage), imagesy($gdImage), $options);
46 $this->gdImage = $gdImage;
47 if ($this->options->readerGrayscale) {
48 imagefilter($this->gdImage, IMG_FILTER_GRAYSCALE);
49 }
50 if ($this->options->readerInvertColors) {
51 imagefilter($this->gdImage, IMG_FILTER_NEGATE);
52 }
53 if ($this->options->readerIncreaseContrast) {
54 imagefilter($this->gdImage, IMG_FILTER_BRIGHTNESS, -100);
55 imagefilter($this->gdImage, IMG_FILTER_CONTRAST, -100);
56 }
57 $this->setLuminancePixels();
58 }
59 /**
60 *
61 */
62 protected function setLuminancePixels() : void
63 {
64 for ($j = 0; $j < $this->height; $j++) {
65 for ($i = 0; $i < $this->width; $i++) {
66 $argb = imagecolorat($this->gdImage, $i, $j);
67 $pixel = imagecolorsforindex($this->gdImage, $argb);
68 $this->setLuminancePixel($pixel['red'], $pixel['green'], $pixel['blue']);
69 }
70 }
71 }
72 /** @inheritDoc */
73 public static function fromFile(string $path, ?SettingsContainerInterface $options = null) : self
74 {
75 return new self(imagecreatefromstring(file_get_contents(self::checkFile($path))), $options);
76 }
77 /** @inheritDoc */
78 public static function fromBlob(string $blob, ?SettingsContainerInterface $options = null) : self
79 {
80 return new self(imagecreatefromstring($blob), $options);
81 }
82 }
83