Combine two plugins focusCrop & Thumbext


I wanted to combine the focuscrop plugin and the thumbext (for automatic retina images).
I tried to change all mentions of the original thumb function in focuscrop into ThumbExt, however it then just shows empy pictures.
Do I need to “import” the thumbext plugin somewhere into the focuscrop source?


I just skipped over the source code of and there should only be two lines, where the thumb() method should be replaces by thumbExt(). The lines where the $image object is returned.

Of course you must also pass the options to the thumbExt() function.

Do you have taken into account, that the thumbExt() function is a function and therefore uses the “old syntax”. Calling this function the same way as $image->thumb() does not work.
(I know, i should give the plugin some love and adapt it to the “new” syntax and also to the new thumb API).

Standard question: Do you have the errors turned on (c::set('debug', true); in you config) and are there any errors?

Jannik, creator of the thumbExt-Plugin

I tried what you said.

pi@kirby /v/w/k/s/p/focus ❯❯❯ diff focus.orig.php focus.php
diff --git a/focus.orig.php b/focus.php
index 595297a..63a6c48 100644
--- a/focus.orig.php
+++ b/focus.php
@@ -94,6 +94,7 @@ file::$methods['focusCrop'] = function($file, $width, $height = null, $quality =
   $params = array();
+  $params['srcset'] = '2x, 3x';
   $params['width'] = $width;
   // if no height is given use width to crop a square
@@ -105,7 +106,7 @@ file::$methods['focusCrop'] = function($file, $width, $height = null, $quality =
   if ($ratioSource == $ratioThumb) {
     // no cropping, just resize 
-    return $file->thumb($params);
+    return $file->ThumbExt($params);
   if ($ratioThumb < $ratioSource) {
@@ -133,10 +134,11 @@ file::$methods['focusCrop'] = function($file, $width, $height = null, $quality =
   $params['filename'] = '{safeName}-' . $params['width'] . 'x' . $params['height'] . '-' . $params['focusX']*100 . '-' . $params['focusY']*100 . '.{extension}';
   // quality set?
   if ($quality) $params['quality'] = $quality;
-  return $file->thumb($params);
+  return $file->ThumbExt($params);

As a result, the thumbs vanish… I do not see any errors, despite debug. where would they show up?


You should do

return ThumbExt($file, $params);

instead of

return $file->ThumbExt($params);

I haven’t tested the syntax you’re trying, but I don’t think, that it would work, because ThumbExt is “only” a normal php function and not registered as a method, that you can apply on the file object.

I don’t know, how much you know about functions and methods in object oriented programming. But the essential thing is, that they have a different syntax in kirby and therefore you cannot call a “normal” php function the same way as every other kirby method.

Error messages are inserted when they occur, so they can be somewhere on your page.

1 Like

This seems to work, thank you!