1111 *
1212 * @package Markenwerk\QrCodeSuite\QrRender
1313 */
14- class QrCodeRendererPng implements Base \QrCodeRendererInterface
14+ class QrCodeRendererPng extends AbstractPixelRenderer implements Base \QrCodeRendererInterface
1515{
1616
17- const MARGIN = 2 ;
18-
1917 /**
2018 * @var RgbColor
2119 */
@@ -26,21 +24,6 @@ class QrCodeRendererPng implements Base\QrCodeRendererInterface
2624 */
2725 private $ backgroundColor ;
2826
29- /**
30- * @var int
31- */
32- private $ approximateSize = 1000 ;
33-
34- /**
35- * @var int
36- */
37- private $ width ;
38-
39- /**
40- * @var int
41- */
42- private $ height ;
43-
4427 /**
4528 * QrCodeRendererPng constructor.
4629 */
@@ -86,43 +69,6 @@ public function setBackgroundColor(RgbColor $backgroundColor)
8669 return $ this ;
8770 }
8871
89- /**
90- * @return int
91- */
92- public function getApproximateSize ()
93- {
94- return $ this ->approximateSize ;
95- }
96-
97- /**
98- * @param int $approximateSize
99- * @return $this
100- */
101- public function setApproximateSize ($ approximateSize )
102- {
103- if (!is_int ($ approximateSize ) || $ approximateSize < 0 || $ approximateSize > 5000 ) {
104- throw new \InvalidArgumentException ('Approximate size has to be a positive integer less than 5000 ' );
105- }
106- $ this ->approximateSize = $ approximateSize ;
107- return $ this ;
108- }
109-
110- /**
111- * @return int
112- */
113- public function getWidth ()
114- {
115- return $ this ->width ;
116- }
117-
118- /**
119- * @return int
120- */
121- public function getHeight ()
122- {
123- return $ this ->height ;
124- }
125-
12672 /**
12773 * @param QrCode $qrCode
12874 * @param string $filename
@@ -139,17 +85,17 @@ public function render(QrCode $qrCode, $filename)
13985 $ height = $ qrCode ->getHeight ();
14086
14187 // Calculate params
142- $ blockSize = round ($ this ->approximateSize / ($ width + 2 * self ::MARGIN ));
143- $ this ->width = ( int )($ width + 2 * self ::MARGIN ) * $ blockSize ;
144- $ this ->height = ( int )($ height + 2 * self ::MARGIN ) * $ blockSize ;
88+ $ blockSize = round ($ this ->getApproximateSize () / ($ width + 2 * self ::MARGIN ));
89+ $ this ->setWidth (( int )($ width + 2 * self ::MARGIN ) * $ blockSize) ;
90+ $ this ->setHeight (( int )($ height + 2 * self ::MARGIN ) * $ blockSize) ;
14591
14692 // Define colors
14793 $ black = new \ImagickPixel ($ this ->foregroundColor ->getHex ());
14894 $ white = new \ImagickPixel ($ this ->backgroundColor ->getHex ());
14995
15096 // Prepare canvas
15197 $ canvas = new \Imagick ();
152- $ canvas ->newImage ($ this ->width , $ this ->height , $ white , "png " );
98+ $ canvas ->newImage ($ this ->getWidth () , $ this ->getHeight () , $ white , "png " );
15399 $ canvas ->setImageColorspace (\Imagick::COLORSPACE_RGB );
154100 $ canvas ->setImageDepth (8 );
155101
@@ -172,7 +118,7 @@ public function render(QrCode $qrCode, $filename)
172118 $ canvas ->drawImage ($ draw );
173119
174120 // Write out the image
175- $ writeSuccess = @ $ canvas ->writeImage ($ filename );
121+ $ writeSuccess = $ canvas ->writeImage ($ filename );
176122 $ canvas ->clear ();
177123 $ canvas ->destroy ();
178124
0 commit comments