phpThumb / pThumb - Ignoring Contexts


I’m unable to get phpThumb / pThumb to work, I’m thinking it may have to do with my multi-site / multi-context setup…(different domains)

Step to reproduce

I have tried uninstalling and reinstalling pThumb a few times with the same result.

Current code:

“photo_a” is the full resolution photo, currently rendering properly as text:

I have also tried setting phpthumb_document_root in the context settings. It does not seem to have taken any affect.

Observed behavior

I’m assuming the final result would be a unique URL to a thumbnail of my photo, instead I’m getting back what I put in: /_files/images/articles/1.jpg.

I’m receiving the following error on installation:

xPDOVehicle validator failed: type php (XXXX/core/packages/pthumb-2.3.3-pl/xPDOTransportVehicle/aea43ca81ababaf9acb1782bbccb4b19.validate.resizer.validator)

I’m seeing this error repeating in the log when I refresh the live page:

[2019-12-24 22:53:10] (ERROR @ XXXX/core/components/phpthumbof/model/phpthumbof.class.php : 156) [pThumb] Resource: 5 || Image: (none)
File not found: XXXX/_files/images/articles/1.jpg  *** Skipping ***
[2019-12-24 22:53:11] (ERROR @ XXXX/core/components/fastfield/model/fastfield/fastfield.php : 97) fastField: Resource `0` doesn't exist
[2019-12-24 22:53:11] (ERROR in resource 5 @ XXXX/core/model/modx/modparser.class.php : 1373) Bad link tag `[[~0]]` encountered

The second line (above) would never work, it’s not the correct path. Somehow I need to add a few folders to that. :thinking:

Here is a screenshot of my current phpThumb settings:


  • MODX: 2.7.1-pl
  • MIGX: 2.12.0-pl
  • PHP: 7.3.3
  • MySQL: 5.1.73 (latin1, latin1_swedish_ci)
  • pThumb 2.3.3-pl


I would like to automatically produce thumbnails of higher-quality photos for lazy loading purposes. Initially I thought I could just use the thumbnail functionality already being produced in the MODX media browser, but I couldn’t get that to work. I’m open to the most efficient way of accomplishing this…any ideas?

Thank you for your help and Merry Christmas to you!

1 Like


I have spent many hours trying to figure this out. I think I have a better understanding of what the issue is, but I’m still stuck. :yawning_face:

I’m using multiple contexts with separate media sources.

Let’s say I have this code in a chunk:
<img src="[[pthumb? &input=`[[+photo_a]]` &options=`w=150&h=150&zc=1`]]">

Where [[+photo_a]] = /_files/images/articles/1.jpg (working perfectly, but this is not the full path from the root, this is a relative path based on the context and domain)

On load I receive the following error in the log:

[2019-12-30 16:09:02] (ERROR @ XXX/core/components/phpthumbof/model/phpthumbof.class.php : 156) [pThumb] Resource: 5 || Image: (none)
File not found: XXX/_files/images/articles/1.jpg  *** Skipping ***

XXX = the full path from the root of my server

The error is correct, the file is not there. The path is missing a couple directories in between. The full path from the root is: XXX/sites/site_a/_files/images/articles/1.jpg.

Why is it ignoring my context?!!!?!

So I changed my code in the chunk to the following, adding in the missing directories:
<img src="/sites/site_a[[pthumb? &input=`[[+photo_a]]` &options=`w=150&h=150&zc=1`]]">

Success, I now have a thumbnail! But wait…Now the file location is based off the root of MODX, not the context/domain root, so it’s not displaying: “/sites/site_a/_files/cache/1.6481d8d1.jpg”.

Instead, it should be: “/_files/cache/1.6481d8d1.jpg”, if I navigate there, it works.

How do I change the output to give me the relative path?!?!?!!?


Here are a full list of my current Context Settings and Media Source Properties:

Am I better off doing this a completely different way?!?!? :sob:

Thanks again for any help you might be able to offer me!

1 Like

I notice that you have basePathRelative set to Yes but your actual basePath is using an absolute path. Have you tried removing the leading slash?

1 Like

Thanks for the reply. Good call.

I just saw this post from @bobray too:

I changed all of the paths to relative, no change. :sob:


I am continuing to play with this, here is the latest log:

[2019-12-31 21:02:10] (ERROR @ XXX/core/components/phpthumbof/model/phpthumbof.class.php : 156) [pThumb] Resource: 5 || Image: _files/images/articles/1.jpg
Could not generate thumbnail
phpThumb debug output:
    [0] => phpThumb() v1.7.15-201902101903 in file "phpthumb.class.php" on line 229
    [1] => setSourceFilename(XXX/_files/images/articles/1.jpg) set $this->sourceFilename to "XXX/_files/images/articles/1.jpg" in file "phpthumb.class.php" on line 294
    [2] => Addding ImageMagick formats to $AvailableImageOutputFormats (text;ico;bmp;wbmp;gif;png;jpeg;webp) in file "phpthumb.class.php" on line 999
    [3] => $AvailableImageOutputFormats = array(text;ico;bmp;wbmp;gif;png;jpeg;webp) in file "phpthumb.class.php" on line 1005
    [4] => $this->thumbnailFormat set to $this->config_output_format "jpeg" in file "phpthumb.class.php" on line 1016
    [5] => $this->thumbnailFormat set to $this->f "jpeg" in file "phpthumb.class.php" on line 1023
    [6] => $this->thumbnailQuality set to "75" in file "phpthumb.class.php" on line 1033
    [7] => ResolveFilenameToAbsolute() prepending $this->config_document_root (sites/site_a/) to $filename (XXX/_files/images/articles/1.jpg) resulting in ($AbsoluteFilename = "sites/site_a//XXX/_files/images/articles/1.jpg") in file "phpthumb.class.php" on line 1338
    [8] => resolvePath: sites/site_a//XXX/_files/images/articles/1.jpg (allowed_dirs: Array

This could be a major part of my issue…it looks like it’s prepending my context path to the full root path of my image. That will never work! My context path needs to be between the path of the image and the root. :skull_and_crossbones:

[7] => ResolveFilenameToAbsolute() prepending $this->config_document_root (sites/site_a/) to $filename (XXX/_files/images/articles/1.jpg) resulting in ($AbsoluteFilename = "sites/site_a//XXX/_files/images/articles/1.jpg") in file "phpthumb.class.php" on line 1338```

Well, I figured out how to break the PHP to make it work for me :angry:…and I did it in a very janky way:

Edit 1

XXX\core\components\phpthumbof\model\phpthumbof.class.php: Line 419-420


$this->phpThumb->setSourceFilename(($this->input[0] === '/' || $this->input[1] === ':') ? $this->input : MODX_BASE_PATH . $this->input);

With this:

$testingthisthing = str_replace('XXX/', 'XXX/' . $this->phpThumb->config_document_root, (($this->input[0] === '/' || $this->input[1] === ':') ? $this->input : MODX_BASE_PATH . $this->input));

Essentially I’m adding in the config_document_root (AKA context path: sites/site_a/) in between the root and the image path. Which gives the proper full path to the root. Not the jacked up one shown in previous posts.

Edit 2

XXX\core\components\phpthumbof\model\phpthumbof.class.php: Line 438


$output['src'] = $cacheUrl;

With this:

$output['src'] = str_replace($this->phpThumb->config_document_root, '', $cacheUrl);

Here I’m doing a bang-up job removing the root path I needed to add for the PHP to see the image…but can’t be there for the sake of my context’s path.

It works, but it’s not a good solution. I know this is really bad programming - if anything, it needs to be re-written. Either way, I figure I’m just missing something else…somewhere…in the UI.

Any ideas anyone? Please? :grimacing:

1 Like

Have you tried the phpThumbOf system settings? There are some path related settings there, including one about a base directory for images, that could have an impact on this. You can sometimes use placeholders and template tags in the paths for settings as well, which would allow you to dynamically set the path based on the media source. Redactor’s file path settings work that way but I don’t know for sure that pThumb can do that tho though.

1 Like

Thanks for the reply @dev_willis. Sorry I haven’t gotten back to you sooner, I’ve been quite sick for the last two weeks. :cold_face:

I don’t think I had tried looking at “phpThumbOf” yet. But I took a look and only see the following two settings come close to your suggestion:

Override Cache Path (phpthumbof.cache_path): You may set an absolute path here to override the path for the cache.


Override Cache URL (phpthumbof.cache_url): An absolute URL to be prepended to generated image URLs. Can be useful when using contexts and subdomains.

Neither of them appear to change anything. Nor do their descriptions seem like something I would want to change.

I’m so confused why I have all of these separate settings, that appear to have the same job, all to change one thing, and none of them appear to work?!?1 :tired_face:

1 Like

No worries. Sorry you’re having so much trouble with this. Those settings you mention definitely sound like they do what you want. If changing them has no effect, and assuming they actually do what they seem to be saying they do, then I would think there’s a cache that needs clearing or maybe there’s a bug in phpThumbOf. The description, with it’s mention of the setting being useful when using contexts, certainly makes it sound like what you need.

As for all the different settings, they do not have the same job nor change the same things and they all do work, at least as far as the system settings go–I can’t vouch for phpThumbOf. They’re just not the settings you’re looking for. There are many things that might need custom path options and nearly everything in MODX is configurable.

@dev_willis, I don’t think my cache path was ever “wrong”, and too much was already being prepended to the url as it is.

What I don’t get is, I have “phpThumb”, “pThumb”, and “phpThumbOf”, they all seem to have their own setting for cache locations and other things! How did I get in this mess? I just need one functioning extra, not three lol. When I modified the one you suggested, nothing happened - almost like it was being overwritten with one of the other very similar settings.

I agree that something is screwed up somewhere. I went through the file (phpthumbof.class.php) and printed 30+ variables trying to figure out what was going on. Based on what I saw in the output, I was unable to determine how I could ever get this to work without modifying it. So I came up with my own fix (below).

This is what I had to do:

Edit 1

XXX\core\components\phpthumbof\model\phpthumbof.class.php : Line 419-420


$this->phpThumb->setSourceFilename(($this->input[0] === '/' || $this->input[1] === ':') ? $this->input : MODX_BASE_PATH . $this->input);`

With this:

$this->phpThumb->setSourceFilename(MODX_BASE_PATH . $this->modx->getOption('base_url') . $src);

I am correcting the output path from this:
XXX/_files/images/articles/1.jpg (which is not even close to the correct folder structure)
to this:

Edit 2 (same file)

XXX\core\components\phpthumbof\model\phpthumbof.class.php : Line 64-65


$this->config['cachePathUrl'] = str_replace(MODX_BASE_PATH, "$cacheurl/", $this->config['cachePath']);

With this:

$this->config['cachePathUrl'] = str_replace(MODX_BASE_PATH . $this->modx->getOption('base_url'), "", $this->config['cachePath']);

I’m just adding the context path in “sites/site_a/”, which wasn’t there otherwise.

Edit 3

Context Setting Change

Changed: Images Base Directory (pthumb.ptcache_images_basedir)
from sites/site_a/_files/images/ to _files/images/

This is probably where all my problems are, in these directory settings…but I had to output this setting next to other variables in the PHP to understand what the path should actually be! :angry:

This took forever to figure out and I’m not too pleased with this solution…but it does work 100% as expected now. My images are being cached in the correct folder, with the correct folder structure, and are also displaying on the site as expected.