woocommerce-pos
/
vendor_prefixed
/
chillerlan
/
php-qrcode
/
src
/
Common
/
IMagickLuminanceSource.php
IMagickLuminanceSource.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.20, at vendor_prefixed/chillerlan/php-qrcode/src/Common/IMagickLuminanceSource.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class IMagickLuminanceSource |
| 5 | * |
| 6 | * @created 17.01.2021 |
| 7 | * @author Ashot Khanamiryan |
| 8 | * @author Smiley <[email protected]> |
| 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\Settings\SettingsContainerInterface; |
| 17 | use Imagick; |
| 18 | use function count; |
| 19 | /** |
| 20 | * This class is used to help decode images from files which arrive as Imagick Resource |
| 21 | * It does not support rotation. |
| 22 | */ |
| 23 | class IMagickLuminanceSource extends LuminanceSourceAbstract |
| 24 | { |
| 25 | protected Imagick $imagick; |
| 26 | /** |
| 27 | * IMagickLuminanceSource constructor. |
| 28 | */ |
| 29 | public function __construct(Imagick $imagick, ?SettingsContainerInterface $options = null) |
| 30 | { |
| 31 | parent::__construct($imagick->getImageWidth(), $imagick->getImageHeight(), $options); |
| 32 | $this->imagick = $imagick; |
| 33 | if ($this->options->readerGrayscale) { |
| 34 | $this->imagick->setImageColorspace(Imagick::COLORSPACE_GRAY); |
| 35 | } |
| 36 | if ($this->options->readerInvertColors) { |
| 37 | $this->imagick->negateImage($this->options->readerGrayscale); |
| 38 | } |
| 39 | if ($this->options->readerIncreaseContrast) { |
| 40 | for ($i = 0; $i < 10; $i++) { |
| 41 | $this->imagick->contrastImage(\false); |
| 42 | // misleading docs |
| 43 | } |
| 44 | } |
| 45 | $this->setLuminancePixels(); |
| 46 | } |
| 47 | /** |
| 48 | * |
| 49 | */ |
| 50 | protected function setLuminancePixels() : void |
| 51 | { |
| 52 | $pixels = $this->imagick->exportImagePixels(1, 1, $this->width, $this->height, 'RGB', Imagick::PIXEL_CHAR); |
| 53 | $count = count($pixels); |
| 54 | for ($i = 0; $i < $count; $i += 3) { |
| 55 | $this->setLuminancePixel($pixels[$i] & 0xff, $pixels[$i + 1] & 0xff, $pixels[$i + 2] & 0xff); |
| 56 | } |
| 57 | } |
| 58 | /** @inheritDoc */ |
| 59 | public static function fromFile(string $path, ?SettingsContainerInterface $options = null) : self |
| 60 | { |
| 61 | return new self(new Imagick(self::checkFile($path)), $options); |
| 62 | } |
| 63 | /** @inheritDoc */ |
| 64 | public static function fromBlob(string $blob, ?SettingsContainerInterface $options = null) : self |
| 65 | { |
| 66 | $im = new Imagick(); |
| 67 | $im->readImageBlob($blob); |
| 68 | return new self($im, $options); |
| 69 | } |
| 70 | } |
| 71 |