@@ -47,6 +47,11 @@ class Image
4747 *
4848 */
4949
50+ /**
51+ * Enable text on image
52+ */
53+ public bool $ textEnabled = false ;
54+
5055 /**
5156 * Font size for the text
5257 */
@@ -812,12 +817,40 @@ public function applyFrame(GdImage $sourceResource): GdImage
812817 }
813818 }
814819
820+ /**
821+ * Helper function to define vars for applyText
822+ */
823+ public function setTextConfig (array $ config , string $ style = 'picture ' , float $ scale = 1.0 ): void
824+ {
825+ $ key = 'texton ' . $ style ;
826+ if (!isset ($ config [$ key ])) {
827+ $ key = 'textonpicture ' ;
828+ }
829+ $ textConfig = $ config [$ key ];
830+
831+ // apply config if defined, fallback to defaults
832+ $ this ->textEnabled = $ textConfig ['enabled ' ] ?? false ;
833+ $ this ->fontPath = $ textConfig ['font ' ] ?? '' ;
834+ $ this ->fontSize = (int ) round (($ textConfig ['font_size ' ] ?? 80 ) * $ scale );
835+ $ this ->fontRotation = $ textConfig ['rotation ' ] ?? 0 ;
836+ $ this ->fontLocationX = (int ) round (($ textConfig ['locationx ' ] ?? 80 ) * $ scale );
837+ $ this ->fontLocationY = (int ) round (($ textConfig ['locationy ' ] ?? 80 ) * $ scale );
838+ $ this ->fontColor = $ textConfig ['font_color ' ] ?? '#ffffff ' ;
839+ $ this ->textLine1 = $ textConfig ['line1 ' ] ?? '' ;
840+ $ this ->textLine2 = $ textConfig ['line2 ' ] ?? '' ;
841+ $ this ->textLine3 = $ textConfig ['line3 ' ] ?? '' ;
842+ $ this ->textLineSpacing = (int ) round (($ textConfig ['linespace ' ] ?? 90 ) * $ scale );
843+ }
844+
815845 /**
816846 * Apply text to the source image resource
817847 */
818848 public function applyText (GdImage $ sourceResource ): GdImage
819849 {
820850 try {
851+ if (!$ this ->textEnabled ) {
852+ return $ sourceResource ;
853+ }
821854 $ fontPath = PathUtility::getAbsolutePath ($ this ->fontPath );
822855 $ tempFontPath = $ _SERVER ['DOCUMENT_ROOT ' ] . '/tempfont.ttf ' ;
823856 $ isTempFont = false ;
0 commit comments