1
1
<?php
2
+ /**
3
+ * Copyright (c) 2019 PHP-QuickORM ImageResize
4
+ * Author: Rytia Leung
5
+
6
+ * Github: github.com/php-quickorm/ImageResize
7
+ */
8
+
2
9
class ImageResize
3
10
{
4
11
private $ path ;
@@ -10,6 +17,13 @@ class ImageResize
10
17
private $ rawResource ;
11
18
private $ newResource ;
12
19
20
+ /**
21
+ * ImageResize constructor.
22
+ * @param string $path
23
+ * @param int $width
24
+ * @param int $height
25
+ * @param string $sourceFormat
26
+ */
13
27
public function __construct ($ path , $ width = 170 , $ height = 128 , $ sourceFormat = null )
14
28
{
15
29
@@ -31,6 +45,9 @@ public function __construct($path, $width = 170, $height = 128, $sourceFormat =
31
45
$ this ->generate ();
32
46
}
33
47
48
+ /**
49
+ * Generate image
50
+ */
34
51
private function generate (){
35
52
// Get new sizes
36
53
list ($ oldWidth , $ oldHeight ) = getimagesize ($ this ->path );
@@ -63,6 +80,15 @@ private function generate(){
63
80
64
81
}
65
82
83
+ /**
84
+ * Add water mark to image
85
+ * @param string $path
86
+ * @param int $width
87
+ * @param int $height
88
+ * @param string $positionX
89
+ * @param string $positionY
90
+ * @param int $margin
91
+ */
66
92
public function addImageMark ($ path , $ width = 50 , $ height = 50 , $ positionX = "right " , $ positionY = "bottom " , $ margin = 10 ){
67
93
68
94
$ im = (new ImageResize ($ path , $ width , $ height ))->getImageResource ();
@@ -83,6 +109,15 @@ public function addImageMark($path, $width = 50, $height = 50, $positionX = "rig
83
109
84
110
}
85
111
112
+ /**
113
+ * Add text to image
114
+ * @param string $text
115
+ * @param int $fontSize
116
+ * @param string $color
117
+ * @param string $positionX
118
+ * @param string $positionY
119
+ * @param int $margin
120
+ */
86
121
public function addTextMark ($ text , $ fontSize = 5 , $ color = "#0000ff " , $ positionX = "right " , $ positionY = "bottom " , $ margin = 10 ){
87
122
88
123
$ textWidth = imagefontwidth ($ fontSize ) * strlen ($ text );
@@ -105,13 +140,21 @@ public function addTextMark($text, $fontSize = 5, $color = "#0000ff", $positionX
105
140
imagestring ( $ this ->newResource , $ fontSize , $ dstX , $ dstY , $ text , $ textColor );
106
141
}
107
142
143
+ /**
144
+ * Get PHP GD resource
145
+ * @return resource
146
+ */
108
147
public function getImageResource ()
109
148
{
110
149
return $ this ->newResource ;
111
150
}
112
151
113
152
114
-
153
+ /**
154
+ * Save the image as file
155
+ * @param string $path
156
+ * @param null $format
157
+ */
115
158
public function save ($ path , $ format = null ){
116
159
117
160
if (is_null ($ format )) {
@@ -137,6 +180,9 @@ public function save($path, $format = null){
137
180
138
181
}
139
182
183
+ /**
184
+ * Send HTTP Response
185
+ */
140
186
public function render (){
141
187
switch ($ this ->extension ){
142
188
case 'jpg ' :
0 commit comments