@@ -63,6 +63,55 @@ private function generate(){
6363
6464 }
6565
66+ public function addImageMark ($ path , $ width = 50 , $ height = 50 , $ positionX = "right " , $ positionY = "bottom " , $ margin = 10 ){
67+
68+ $ im = (new ImageResize ($ path , $ width , $ height ))->getImageResource ();
69+
70+ if (strtolower ($ positionX ) == "right " ){
71+ $ dstX = $ this ->width - $ width - $ margin ;
72+ } else {
73+ $ dstX = $ margin ;
74+ }
75+
76+ if (strtolower ($ positionY ) == "bottom " ){
77+ $ dstY = $ this ->height - $ height - $ margin ;
78+ } else {
79+ $ dstY = $ margin ;
80+ }
81+
82+ imagecopy ($ this ->newResource , $ im , $ dstX , $ dstY , 0 , 0 , $ width , $ height );
83+
84+ }
85+
86+ public function addTextMark ($ text , $ fontSize = 5 , $ color = "#0000ff " , $ positionX = "right " , $ positionY = "bottom " , $ margin = 10 ){
87+
88+ $ textWidth = imagefontwidth ($ fontSize ) * strlen ($ text );
89+ $ textHeight = imagefontheight ($ fontSize );
90+
91+ if (strtolower ($ positionX ) == "right " ){
92+ $ dstX = $ this ->width - $ textWidth - $ margin ;
93+ } else {
94+ $ dstX = $ margin ;
95+ }
96+
97+ if (strtolower ($ positionY ) == "bottom " ){
98+ $ dstY = $ this ->height - $ textHeight - $ margin ;
99+ } else {
100+ $ dstY = $ margin ;
101+ }
102+
103+ $ textColor = imagecolorallocate ($ this ->newResource , hexdec ($ color [1 ].$ color [2 ]), hexdec ($ color [3 ].$ color [4 ]), hexdec ($ color [5 ].$ color [6 ]));
104+
105+ imagestring ( $ this ->newResource , $ fontSize , $ dstX , $ dstY , $ text , $ textColor );
106+ }
107+
108+ public function getImageResource ()
109+ {
110+ return $ this ->newResource ;
111+ }
112+
113+
114+
66115 public function save ($ path , $ format = null ){
67116
68117 if (is_null ($ format )) {
@@ -104,7 +153,4 @@ public function render(){
104153 break ;
105154 }
106155 }
107- }
108-
109- $ a = new ImageResize ('test.jpg ' ,170 ,128 );
110- $ a ->save ('a.png ' );
156+ }
0 commit comments