0

When I uploaded an image ( example: user/1/user_profile_img.jpg ), I want intervention image to create multiple thumbnail sizes ( 100x100, 200x200, 400x400 etc ), these sizes will be use in different pages to improve the pagespeed score.

Should I store the different thumbnail sizes ( 100x100, 200x200, 400x400 etc ) in a custom /cache/ folder? like '/cache/user/1/user_profile_img-100x100.jpg'?

or I generate them when the page is visited with the intervention image cache resize route like:

{{ route('photos/item/100x100/userprofile/user_profile_img.jpg') }}

in the blade.php template?

Route::get('photos/item/{size}/{reference}/{photo}', 'ImgController@showImg');

I saw there is a 'lifetime (optional)' parameter in the Intervention Image Cache function:

$img = Image::cache(function($image) {
   $image->make('public/foo.jpg')->resize(300, 200)->greyscale();
}, 10, true);

The lifetime in minutes of the image callback in the cache.

Is it for setting the image cache expiry time?

Will the image be auto deleted from /cache/ folder?

thisiskelvin
  • 4,136
  • 1
  • 10
  • 17
vasiline
  • 55
  • 1
  • 6

1 Answers1

1

Should I store the different thumbnail sizes [...] or I generate them when the page is visited [...]?

Resizing images can take a long time relative to the duration of a typical web request. If speed is important to you then I would definitely recommend saving the resized versions when the image is initially uploaded, either during the upload request itself or in a job which is dispatched by the upload controller action.

If you use the caching features of the Intervention package then you might end up with pages often needing to be "warmed up" when the resized images haven't been cached recently. However, this would depend on your traffic patterns, which cache implementation was used, and the cache duration. If you try it and it seems to work for your use case then there's nothing wrong with using it.

Travis Britz
  • 5,094
  • 2
  • 20
  • 35