@@ -32,7 +32,8 @@ public static function render(TextImage $textImage)
32
32
$ textImage ->getFullHeight (),
33
33
$ textImage ->getBorder (),
34
34
$ textImage ->getBackgroundColor (),
35
- $ textImage ->getBorderColor ()
35
+ $ textImage ->getBorderColor (),
36
+ $ textImage ->getTransparentBackground ()
36
37
);
37
38
$ textOffset = $ textImage ->getTextOffset ();
38
39
foreach ($ textImage ->getLines () as $ line ) {
@@ -62,24 +63,35 @@ public static function render(TextImage $textImage)
62
63
* @param array $border
63
64
* @param Objects\Color $backgroundColor
64
65
* @param Objects\Color $borderColor
66
+ * @param bool $transparentBackground
65
67
* @return resource
66
68
*/
67
- private static function createEmptyImage ($ width , $ height , array $ border , Objects \Color $ backgroundColor , Objects \Color $ borderColor )
69
+ private static function createEmptyImage ($ width , $ height , array $ border , Objects \Color $ backgroundColor , Objects \Color $ borderColor, $ transparentBackground )
68
70
{
69
71
$ image = imagecreatetruecolor ($ width , $ height );
70
- $ backColor = Objects \Color::allocateToImage ($ image , $ backgroundColor );
71
- $ bordColor = Objects \Color::allocateToImage ($ image , $ borderColor );
72
- // Border
73
- imagefilledrectangle ($ image , 0 , 0 , $ width , $ height , $ bordColor );
74
- // Background
75
- imagefilledrectangle (
76
- $ image ,
77
- $ border [TextImage::OPT_LEFT ],
78
- $ border [TextImage::OPT_TOP ],
79
- ($ width - $ border [TextImage::OPT_RIGHT ]),
80
- ($ height - $ border [TextImage::OPT_BOTTOM ]),
81
- $ backColor
82
- );
72
+
73
+ if ($ transparentBackground === TRUE ) {
74
+ imagealphablending ($ image , false );
75
+ $ transparency = imagecolorallocatealpha ($ image , 0 , 0 , 0 , 127 );
76
+ imagefill ($ image , 0 , 0 , $ transparency );
77
+ imagesavealpha ($ image , true );
78
+ } else {
79
+ $ backColor = Objects \Color::allocateToImage ($ image , $ backgroundColor );
80
+ $ bordColor = Objects \Color::allocateToImage ($ image , $ borderColor );
81
+
82
+ // Border
83
+ imagefilledrectangle ($ image , 0 , 0 , $ width , $ height , $ bordColor );
84
+ // Background
85
+ imagefilledrectangle (
86
+ $ image ,
87
+ $ border [TextImage::OPT_LEFT ],
88
+ $ border [TextImage::OPT_TOP ],
89
+ ($ width - $ border [TextImage::OPT_RIGHT ]),
90
+ ($ height - $ border [TextImage::OPT_BOTTOM ]),
91
+ $ backColor
92
+ );
93
+ }
94
+
83
95
return $ image ;
84
96
}
85
97
0 commit comments