@@ -47,7 +47,7 @@ class sfImageThumbnailGeneric extends sfImageTransformAbstract
47
47
/**
48
48
* available methods for thumbnail creation
49
49
*/
50
- protected $ methods = array ('fit ' , 'scale ' , 'inflate ' ,'deflate ' , 'left ' ,'right ' , 'top ' , 'bottom ' , 'center ' );
50
+ protected $ methods = array ('fit ' , 'scale ' , 'inflate ' ,'deflate ' , 'left ' ,'right ' , 'top ' , 'bottom ' , 'center ' , ' top-left ' , ' top-right ' , ' bottom-left ' , ' bottom-right ' );
51
51
52
52
/*
53
53
* background color in hex or null for transparent
@@ -195,40 +195,53 @@ protected function transform(sfImage $image)
195
195
196
196
$ scale_w = $ this ->getWidth ()/$ resource_w ;
197
197
$ scale_h = $ this ->getHeight ()/$ resource_h ;
198
- switch ($ this ->getMethod ())
198
+ $ method = $ this ->getMethod ();
199
+ switch ($ method )
199
200
{
200
201
case 'deflate ' :
201
202
case 'inflate ' :
202
203
203
204
return $ image ->resize ($ this ->getWidth (), $ this ->getHeight ());
204
205
205
206
case 'left ' :
206
- $ image ->scale (max ($ scale_w , $ scale_h ));
207
-
208
- return $ image ->crop (0 , (int )round (($ image ->getHeight () - $ this ->getHeight ()) / 2 ), $ this ->getWidth (), $ this ->getHeight ());
209
-
210
207
case 'right ' :
211
- $ image ->scale (max ($ scale_w , $ scale_h ));
212
-
213
- return $ image ->crop (($ image ->getWidth () - $ this ->getWidth ()), (int )round (($ image ->getHeight () - $ this ->getHeight ()) / 2 ),$ this ->getWidth (), $ this ->getHeight ());
214
-
215
208
case 'top ' :
216
- $ image ->scale (max ($ scale_w , $ scale_h ));
217
-
218
- return $ image ->crop ((int )round (($ image ->getWidth () - $ this ->getWidth ()) / 2 ), 0 , $ this ->getWidth (), $ this ->getHeight ());
219
-
220
209
case 'bottom ' :
221
- $ image -> scale ( max ( $ scale_w , $ scale_h ));
222
-
223
- return $ image -> crop (( int ) round (( $ image -> getWidth () - $ this -> getWidth ()) / 2 ), ( $ image -> getHeight () - $ this -> getHeight ()), $ this -> getWidth (), $ this -> getHeight ());
224
-
210
+ case ' top-left ' :
211
+ case ' top-right ' :
212
+ case ' bottom-left ' :
213
+ case ' bottom-right ' :
225
214
case 'center ' :
226
215
$ image ->scale (max ($ scale_w , $ scale_h ));
227
-
228
- $ left = (int )round (($ image ->getWidth () - $ this ->getWidth ()) / 2 );
229
- $ top = (int )round (($ image ->getHeight () - $ this ->getHeight ()) / 2 );
216
+
217
+ if (false !== strstr ($ method , 'top ' ))
218
+ {
219
+ $ top = 0 ;
220
+ }
221
+ else if (false !== strstr ($ method , 'bottom ' ))
222
+ {
223
+ $ top = $ image ->getHeight () - $ this ->getHeight ();
224
+ }
225
+ else
226
+ {
227
+ $ top = (int )round (($ image ->getHeight () - $ this ->getHeight ()) / 2 );
228
+ }
229
+
230
+ if (false !== strstr ($ method , 'left ' ))
231
+ {
232
+ $ left = 0 ;
233
+ }
234
+ else if (false !== strstr ($ method , 'right ' ))
235
+ {
236
+ $ left = $ image ->getWidth () - $ this ->getWidth ();
237
+ }
238
+ else
239
+ {
240
+ $ left = (int )round (($ image ->getWidth () - $ this ->getWidth ()) / 2 );
241
+ }
230
242
231
243
return $ image ->crop ($ left , $ top , $ this ->getWidth (), $ this ->getHeight ());
244
+
232
245
case 'scale ' :
233
246
return $ image ->scale (min ($ scale_w , $ scale_h ));
234
247
0 commit comments