CakePhP3: Creating Thumbnails for images after upload

Hi All

I am successfully using Jose Gonzalez’s Upload plugin in my CRUD forms to upload photos of garments.

But I need to create at least one 150x150 pixel thumbnail. I have added Florian Krämer’s Imagine plugin to my composer.json file.

I have added the following to the PhotosTable.php to the initialize method.


And have the following code in the afterSave method.

    $imageOperations = [
    'thumbnail' => [
    'height' => 600,
    'width' => 200

But I get

Table “App\Model\Table\PhotosTable” is not associated with “imagineObject”

Any ideas? I’m assuming afterSave is the best place to do this?


I think, as the book says you should call like this

Thanks for the suggestion Raul - bu tI already tried that…

Not an answer to your question I’m afraid, but I highly recommend using Glide by the phpleague:

It allows you to manipulate your images on the fly, so if you need to create a particular thumbnail, you simply create a link to the image and add some parameters. Glide then automatically creates and displays the desired image file (well, a bit of configuration is necessary, but only once).

It can be a big pain to create thumbnails manually especially after the upload, but with Glide you just don’t have to worry about any of that anymore. There’s also a Glide plugin especially for Cakephp and it’s fairly easy to get it to work (but the cake plugin is not absolutely necessary).

So yeah, maybe this helps someone since I feel like not many people have even heard about this option.

Turns out I needed to use $this->processImage(…);


1 Like