@@ -346,10 +346,10 @@ public function generateStripThumbnail(Image_Backend $backend) {
346
346
* @param integer $height The height to size to
347
347
* @return Image
348
348
*/
349
- public function PaddedImage ($ width , $ height ) {
349
+ public function PaddedImage ($ width , $ height, $ backgroundColor = null ) {
350
350
return $ this ->isSize ($ width , $ height )
351
351
? $ this
352
- : $ this ->getFormattedImage ('PaddedImage ' , $ width , $ height );
352
+ : $ this ->getFormattedImage ('PaddedImage ' , $ width , $ height, $ backgroundColor );
353
353
}
354
354
355
355
/**
@@ -360,8 +360,8 @@ public function PaddedImage($width, $height) {
360
360
* @param integer $height The height to size to
361
361
* @return Image_Backend
362
362
*/
363
- public function generatePaddedImage (Image_Backend $ backend , $ width , $ height ) {
364
- return $ backend ->paddedResize ($ width , $ height );
363
+ public function generatePaddedImage (Image_Backend $ backend , $ width , $ height, $ backgroundColor = null ) {
364
+ return $ backend ->paddedResize ($ width , $ height, $ backgroundColor );
365
365
}
366
366
367
367
/**
@@ -399,17 +399,20 @@ public function isHeight($height) {
399
399
* Return an image object representing the image in the given format.
400
400
* This image will be generated using generateFormattedImage().
401
401
* The generated image is cached, to flush the cache append ?flush=1 to your URL.
402
+ *
403
+ * Just pass the correct number of parameters expected by the working function
404
+ *
402
405
* @param string $format The name of the format.
403
- * @param string $arg1 An argument to pass to the generate function.
404
- * @param string $arg2 A second argument to pass to the generate function.
405
406
* @return Image_Cached
406
407
*/
407
- public function getFormattedImage ($ format , $ arg1 = null , $ arg2 = null ) {
408
+ public function getFormattedImage ($ format ) {
409
+ $ args = func_get_args ();
410
+
408
411
if ($ this ->ID && $ this ->Filename && Director::fileExists ($ this ->Filename )) {
409
- $ cacheFile = $ this -> cacheFilename ( $ format , $ arg1 , $ arg2 );
410
-
412
+ $ cacheFile = call_user_func_array ( array ( $ this , " cacheFilename " ) , $ args );
413
+
411
414
if (!file_exists (Director::baseFolder ()."/ " .$ cacheFile ) || isset ($ _GET ['flush ' ])) {
412
- $ this -> generateFormattedImage ( $ format , $ arg1 , $ arg2 );
415
+ call_user_func_array ( array ( $ this , " generateFormattedImage " ) , $ args );
413
416
}
414
417
415
418
$ cached = new Image_Cached ($ cacheFile );
@@ -422,14 +425,14 @@ public function getFormattedImage($format, $arg1 = null, $arg2 = null) {
422
425
/**
423
426
* Return the filename for the cached image, given it's format name and arguments.
424
427
* @param string $format The format name.
425
- * @param string $arg1 The first argument passed to the generate function.
426
- * @param string $arg2 The second argument passed to the generate function.
427
428
* @return string
428
429
*/
429
- public function cacheFilename ($ format , $ arg1 = null , $ arg2 = null ) {
430
+ public function cacheFilename ($ format ) {
431
+ $ args = func_get_args ();
432
+ array_shift ($ args );
430
433
$ folder = $ this ->ParentID ? $ this ->Parent ()->Filename : ASSETS_DIR . "/ " ;
431
434
432
- $ format = $ format .$ arg1 . $ arg2 ;
435
+ $ format = $ format .implode ( '' , $ args ) ;
433
436
434
437
return $ folder . "_resampled/ $ format- " . $ this ->Name ;
435
438
}
@@ -440,11 +443,11 @@ public function cacheFilename($format, $arg1 = null, $arg2 = null) {
440
443
* using the specific 'generate' method for the specified format.
441
444
*
442
445
* @param string $format Name of the format to generate.
443
- * @param string $arg1 Argument to pass to the generate method.
444
- * @param string $arg2 A second argument to pass to the generate method.
445
446
*/
446
- public function generateFormattedImage ($ format , $ arg1 = null , $ arg2 = null ) {
447
- $ cacheFile = $ this ->cacheFilename ($ format , $ arg1 , $ arg2 );
447
+ public function generateFormattedImage ($ format ) {
448
+ $ args = func_get_args ();
449
+
450
+ $ cacheFile = call_user_func_array (array ($ this , "cacheFilename " ), $ args );
448
451
449
452
$ backend = Injector::inst ()->createWithArgs (self ::$ backend , array (
450
453
Director::baseFolder ()."/ " . $ this ->Filename
@@ -454,7 +457,11 @@ public function generateFormattedImage($format, $arg1 = null, $arg2 = null) {
454
457
455
458
$ generateFunc = "generate $ format " ;
456
459
if ($ this ->hasMethod ($ generateFunc )){
457
- $ backend = $ this ->$ generateFunc ($ backend , $ arg1 , $ arg2 );
460
+
461
+ array_shift ($ args );
462
+ array_unshift ($ args , $ backend );
463
+
464
+ $ backend = call_user_func_array (array ($ this , $ generateFunc ), $ args );
458
465
if ($ backend ){
459
466
$ backend ->writeTo (Director::baseFolder ()."/ " . $ cacheFile );
460
467
}
0 commit comments