9
9
*/
10
10
class ImageResize
11
11
{
12
- const cropTOP = 1 ;
13
- const cropCENTRE = 2 ;
14
- const cropCENTER = 2 ;
15
- const cropBOTTOM = 3 ;
16
- const cropLEFT = 4 ;
17
- const cropRIGHT = 5 ;
12
+ const CROPTOP = 1 ;
13
+ const CROPCENTRE = 2 ;
14
+ const CROPCENTER = 2 ;
15
+ const CROPBOTTOM = 3 ;
16
+ const CROPLEFT = 4 ;
17
+ const CROPRIGHT = 5 ;
18
18
19
19
public $ quality_jpg = 75 ;
20
20
public $ quality_png = 0 ;
@@ -70,7 +70,7 @@ public static function createFromString($imageData){
70
70
* @param string|null $filename
71
71
* @throws \Exception
72
72
*/
73
- public function __construct ($ filename= null )
73
+ public function __construct ($ filename = null )
74
74
{
75
75
if (!empty ($ filename )) {
76
76
$ this ->load ($ filename );
@@ -135,18 +135,19 @@ public function load($filename)
135
135
switch ($ this ->source_type ) {
136
136
case IMAGETYPE_GIF :
137
137
$ this ->source_image = imagecreatefromgif ($ filename );
138
- break ;
138
+ break ;
139
139
140
140
case IMAGETYPE_JPEG :
141
141
$ this ->source_image = imagecreatefromjpeg ($ filename );
142
- break ;
142
+ break ;
143
143
144
144
case IMAGETYPE_PNG :
145
145
$ this ->source_image = imagecreatefrompng ($ filename );
146
- break ;
146
+ break ;
147
147
148
148
default :
149
149
throw new \Exception ('Unsupported image type ' );
150
+ break ;
150
151
}
151
152
152
153
return $ this ->resize ($ this ->getSourceWidth (), $ this ->getSourceHeight ());
@@ -172,17 +173,17 @@ public function save($filename, $image_type = null, $quality = null, $permission
172
173
imagecolortransparent ($ dest_image , $ background );
173
174
imagefill ($ dest_image , 0 , 0 , $ background );
174
175
imagesavealpha ($ dest_image , true );
175
- break ;
176
+ break ;
176
177
177
178
case IMAGETYPE_JPEG :
178
179
$ background = imagecolorallocate ($ dest_image , 255 , 255 , 255 );
179
180
imagefilledrectangle ($ dest_image , 0 , 0 , $ this ->getDestWidth (), $ this ->getDestHeight (), $ background );
180
- break ;
181
+ break ;
181
182
182
183
case IMAGETYPE_PNG :
183
184
imagealphablending ($ dest_image , false );
184
185
imagesavealpha ($ dest_image , true );
185
- break ;
186
+ break ;
186
187
}
187
188
188
189
imagecopyresampled (
@@ -201,23 +202,23 @@ public function save($filename, $image_type = null, $quality = null, $permission
201
202
switch ($ image_type ) {
202
203
case IMAGETYPE_GIF :
203
204
imagegif ($ dest_image , $ filename );
204
- break ;
205
+ break ;
205
206
206
207
case IMAGETYPE_JPEG :
207
208
if ($ quality === null ) {
208
209
$ quality = $ this ->quality_jpg ;
209
210
}
210
211
211
212
imagejpeg ($ dest_image , $ filename , $ quality );
212
- break ;
213
+ break ;
213
214
214
215
case IMAGETYPE_PNG :
215
216
if ($ quality === null ) {
216
217
$ quality = $ this ->quality_png ;
217
218
}
218
219
219
220
imagepng ($ dest_image , $ filename , $ quality );
220
- break ;
221
+ break ;
221
222
}
222
223
223
224
if ($ permissions ) {
@@ -351,7 +352,7 @@ public function resize($width, $height, $allow_enlarge = false)
351
352
* @param integer $position
352
353
* @return \static
353
354
*/
354
- public function crop ($ width , $ height , $ allow_enlarge = false , $ position = self ::cropCENTER )
355
+ public function crop ($ width , $ height , $ allow_enlarge = false , $ position = self ::CROPCENTER )
355
356
{
356
357
if (!$ allow_enlarge ) {
357
358
// this logic is slightly different to resize(),
@@ -435,17 +436,18 @@ public function getDestHeight()
435
436
* @param integer $position
436
437
* @return integer
437
438
*/
438
- protected function getCropPosition ($ expectedSize , $ position = self ::cropCENTER )
439
+ protected function getCropPosition ($ expectedSize , $ position = self ::CROPCENTER )
439
440
{
440
441
$ size = 0 ;
441
442
switch ($ position ) {
442
- case self ::cropBOTTOM :
443
- case self ::cropRIGHT :
443
+ case self ::CROPBOTTOM :
444
+ case self ::CROPRIGHT :
444
445
$ size = $ expectedSize ;
445
446
break ;
446
- case self ::cropCENTER :
447
- case self ::cropCENTRE :
447
+ case self ::CROPCENTER :
448
+ case self ::CROPCENTRE :
448
449
$ size = $ expectedSize / 2 ;
450
+ break ;
449
451
}
450
452
return $ size ;
451
453
}
0 commit comments