How to get faster image resizing in MODX 3?

I use pThumb on all my sites, and since moving some sites to MODX3, I’ve had to turn off Resizer, since it doesn’t work well with the new MODX and PHP 8.x. Image resizing using pThumb is now significantly slower. Pages with lots of images are taking a long time to load before they’re cached.

Has anyone found ways to speed up image resizing?

It sounds like Resizer’s Imagine dependency is overdue for an update.

Do you know why without Resizer it is so much slower for you?
Is it that you can use the image library “Gmagick” that is not supported in phpThumb?
Otherwise (if the same image library is used), I don’t see why there would be much difference in execution time.


Unfortunately it’s not that simple.
Breaking changes were made to Imagine with the change from version 0.7.1 to 1.0.0 (august 2018). This breaks the code in Reductionist (as explained in this post by sepiariver from september 2019).


Resizer
The MODX extra. Just a wrapper for Reductionist (with basically no code).

Reductionist
A Composer package that uses Imagine to create thumbnails.

Imagine
Image manipulation library that provides an API for all low level image processing libraries in PHP (GD, Imagick, Gmagick).


I looked at the code of Reductionist and unfortunately I don’t understand why the code was written the way it is. There is a lot of code that is specific to the image processing library (GD, Imagick, Gmagick) that is actually used.
What is the point of using an abstraction like Imagine, if so much code is still different for different image processing libraries?

Personally I see two ways to proceed forward.

  • Either officially declaring Resizer/Reductionist as discontinued, setting the repositories to read only and eventually removing Resizer from the pThumb extra.
  • Or trying to change Resizer/Reductionist to use the latest version of Imagine by throwing out a lot of the code in Reductionist and introducing breaking changes (like removing the ability to create watermarks).

Sepiariver made a attempt to implement the later (Reductionist repo, Resizer repo), but that experiment seems to be have been abandoned a long time ago.

1 Like

Reductionist is AFAIK meant to be a replacement for phpThumb using the same properties for image modifications.

Yes, the problem is that when you install the latest version of pThumb, it comes with Resizer 1.0.1-pl that uses 10-year-old code for Reductionist and the Imagine library.

You can upgrade to Resizer 1.0.2-beta. That gives you 7-year-old Imagine code that still doesn’t support WebP or PHP 8. So on a current server environment, this is not a viable replacement for phpThumb.

No, Gmagick is not turned on. PHP has “gd” turned on, and “imagick” turned off. Should I enable “imagick”?


I just enabled imagick, and it still took 16 seconds to generate 15 scaled down images. The originals are between 5 and 12 MB in size.

I used to use ResizeImageOnUpload, but that doesn’t seem to work with MODX 3 (or maybe it’s a PHP version problem).

So how long would it take with Resizer in comparison?
Is this just a resizing or do you do other stuff (like using filters, watermark, etc.)?


Maybe this topic helps:

I’ve taken to not using any of these modx resizers because most are based on ancient code, or as the OP notes - just don’t perform well. The path of least resistance is to move your image resizing to the edge, using something like Cloudflare Images. Some of these providers have free tiers which are fine for small and medium sized sites.

@snowcreative I’ve create a new experimental version of Resizer. This version is only for MODX 3. It uses the current version of the Imagine library and should work with PHP 8. (It no longer supports the watermark filter though.)

It’s largely untested, but if you want, you can try it out and see if it indeed works faster than pThumb with the phpThumb library on your system.

The transport-package is here on Github:

Gave that a try, but generated errors:

Fatal error : Uncaught Error: Call to undefined method Imagine\Imagick\Image::getFormat() in /core/components/resizer/src/Reductionist.php:360

This is with using pThumb, and setting the phpthumbof system setting “Use Resizer” to “yes”.

I see. Just deleting half of the code and hoping everything still works probably wasn’t the best idea. :wink:


You could replace line 360

if ($scale <= 0.5 && $this->gLib && $image->getFormat() === IMG_JPG) {

with this

if ($scale <= 0.5 && $this->gLib && getimagesize($input)[2] === IMG_JPG) {

to fix the error.


At this point I’m mostly interested if there is a significant speed difference between Imagine and the default phpThumb, to see if it is worth investing more time to understand and fix the rest of the code.


Yes, that is correct.
You could also try changing to GD (resizer.graphics_library = 0) as there wasn’t special code for GD that I deleted.

Yes, that worked.

So on a page with a bunch of large images being resized it took:

pThumb with Resizer with iMagick: 33 seconds
pThumb with Resizer with GD: 18 seconds
pThumb without Resizer with GD: 18 seconds

So, no difference at all using Resizer on this MODX 3 site.

Resizer was always billed as being faster, and that was my experience (and still is on some older sites). No idea why.

I believe when Resizer was created, there were performance issues with the phpThumb library. It seems they have been fixed in the meantime. :wink:
It’s also weird that iMagick is so much slower.


All in all, with these results, I don’t think there is much point in investing more time to keep the Resizer extra up-to-date.

2 Likes

Yes it is weird, it shouldn’t be.

@snowcreative For faster image processing in PHP, do you have the ability to install php-vips on your hosting? This can then be combined with Resizer (really the Imagine library) and GitHub - rokka-io/imagine-vips: libvips adapter for php imagine and used to do resizing.