Hi there,
Iāve been having some issues with resizing images on upload which have been really driving me crazy.
Basically all I want to acheive is this: when images are uploaded, resize each one so I can generate a src-set of images to be used in the frontend. I have acheived this with a hook (originally found here), implemented in my config as follows:
<?php
return [
'thumbs' => [
'driver' => 'gd',
],
'hooks' => [
'file.create:after' => function($file) {
$widths = [25, 600, 900, 1200, 1600, 2000];
if ($file->isResizable()) {
foreach($widths as $width) {
try {
$resizedImage = $file->resize($width, null, 80)->save();
}
catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
}
else {
throw new Exception('the file is not resizable');
}
}
]
];
?>
My problem is this: my client will likely upload multiple images at a time (approx. 10-20), and on my server attempting to do always throws the following error when so many images (all between 1-2MB) are uploaded, this usually occurs on the same set of images:
The file could not be uploaded
As I said, the images are roughly the same size in memory. The only strange thing I noticed is this typically happens to the images with the largest pixel dimension, for now I can only assume this is a coincidence, as I have already set max dimensions in my file blueprint (both height and width) to be way above the size of any of the images.
When large images are uploaded individually, there is no problem and all resized images are generated. There is also no issue when attempting to upload in bulk on my local server.
Of course, the first thing I thought this could be would be server time, but even after setting the following variables to be ridiculously generous in my php.ini (see below) I still have the same problem.
I am running php 7.2 on apache, below are the relevant values in my php.ini:
max_execution_time = 5000M
max_file_uploads = 30
max_input_time = -1
memory_limit = 1000M
post_max_size = 500M
upload_max_filesize = 20M
GD library is installed, as are all other necessary modules for Kirby. It is important for my client this works on upload, so I would like to stick with this rather than them being generated on the fly in the frontend.
Any help is much appreciated!
Nick