gabriel007's avatar

How to handle slow image processing

I am referring to the process that takes place after submitting the uploaded files, and not to the upload process.

I am using Intervention/image to process uploaded images. My controller creates a thumbnail and a mid-sized version for each uploaded image.

This works fine when uploading 2-3 pictures, but when uploading over 10 pictures, the processing time takes on average about 4-8 seconds to complete (after clicking the Save button). The higher the number of pictures, the longer it takes.

What I have tried so far:

  • Deferred the cropping part to a queue. This worked fine, but it did not helped with shortening the processing time in any way.
  • Removed image processing altogether. This did speed up the saving process (obviously).

I believe that is not acceptable. How is this normally handled?

0 likes
3 replies
jekinney's avatar

What I do is have an original image column. Upload original and any other image fields are nullable or generic image (see below).

Fire a queued event to manipulate the images. So you're not waiting. It processes the images in the background.

Now if you need to redirect to the page that shows the images you can: set a default of image processing or use the original and CSS to resize as needed till they are processed

1 like
gabriel007's avatar

Thanks jekinney. Indeed, I need to show the processed images on the next screen, after saving.

I didn't think of showing the original & CSS to while processing happens in the background. To be honest I was trying to avoid using queued events (due to having the "listen" run by a supervisor) - but I will actually look at this, and see where it goes.

gabriel007's avatar

In order to solve this, I have implemented thephpleague/glide library.

I only have the original images saved, and I resize them "on demand", like so (using size presets): http://localhost/img/image1.jpg?p=small

They are also is cached, and re-used.

In this way, I would not have to output two different versions of the image or do any processing. The storing process takes now about a second - regardless of the number of files uploaded. Not perfect, but acceptable.

There were probably other ways to solve this issue, however this works fine for me.

Please or to participate in this conversation.