@@ -39,6 +39,43 @@ public function write(QrCodeInterface $qrCode, ?LogoInterface $logo = null, ?Lab
39
39
}
40
40
}
41
41
42
+ if ($ logo instanceof LogoInterface) {
43
+ $ this ->addLogo ($ logo , $ lines , $ matrix ->getOuterSize ());
44
+ }
45
+
42
46
return new EpsResult ($ matrix , $ lines );
43
47
}
48
+
49
+ private function addLogo (LogoInterface $ logo , array &$ lines , int $ outerSize ): void
50
+ {
51
+ $ logoPath = $ logo ->getPath ();
52
+ $ logoHeight = $ logo ->getResizeToHeight ();
53
+ $ logoWidth = $ logo ->getResizeToWidth ();
54
+
55
+ if (null === $ logoHeight || null === $ logoWidth ) {
56
+ $ imageSize = \getimagesize ($ logoPath );
57
+ if (!$ imageSize ) {
58
+ throw new \Exception (sprintf ('Unable to read image size for logo "%s" ' , $ logoPath ));
59
+ }
60
+ [$ logoSourceWidth , $ logoSourceHeight ] = $ imageSize ;
61
+
62
+ if (null === $ logoWidth ) {
63
+ $ logoWidth = (int ) $ logoSourceWidth ;
64
+ }
65
+
66
+ if (null === $ logoHeight ) {
67
+ $ aspectRatio = $ logoWidth / $ logoSourceWidth ;
68
+ $ logoHeight = (int ) ($ logoSourceHeight * $ aspectRatio );
69
+ }
70
+ }
71
+
72
+ $ logoX = $ outerSize / 2 - $ logoWidth / 2 ;
73
+ $ logoY = $ outerSize / 2 - $ logoHeight / 2 ;
74
+
75
+ $ lines [] = 'gsave ' ;
76
+ $ lines [] = number_format ($ logoX , self ::DECIMAL_PRECISION , '. ' , '' ).' ' .number_format ($ logoY , self ::DECIMAL_PRECISION , '. ' , '' ).' translate ' ;
77
+ $ lines [] = number_format ($ logoWidth , self ::DECIMAL_PRECISION , '. ' , '' ).' ' .number_format ($ logoHeight , self ::DECIMAL_PRECISION , '. ' , '' ).' scale ' ;
78
+ $ lines [] = '( ' .$ logoPath .') run ' ;
79
+ $ lines [] = 'grestore ' ;
80
+ }
44
81
}
0 commit comments