Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Xanger's avatar

Generate thumbnails without storing them

Hi, in my old project (I did not use Laravel), i created thumbnails with TimThumb and I had addresses like domain.ddt/upload/426x209-e6fcd4a.jpg

I've already seen Intervention Image(http://image.intervention.io), but as I understand, all the thumbnails are saved, Is there anything to generate thumbnails dynamically?

0 likes
9 replies
Xanger's avatar

Glide unfortunately I could not use it without using the storage, That is why I decided to try with Intervention Image Cache, and it seems to work but...

I just managed to get a link like:

/thumbs/133x124?src=upload/news/news_110cfe3247815927e0624116215f5066.jpg

How do I get an address like:

/thumbs/upload/news/133x124-news_110cfe3247815927e0624116215f5066.jpg

I would like to remove this "?src="

My route code is as follows:

Route::get('thumbs/{imgw}x{imgh}/', function ($imgw,$imgh)
{
    $src = \Input::get('src', 1);
    $width = $imgw;
    $height = $imgh;

    $cacheimage = \Image::cache(function($image) use ($src,$width,$height) {
        return $image->make($src)->resize($width,$height);
    }, 1, false);
    return Response::make($cacheimage, 200, array('Content-Type' => 'image/jpeg'));
});
martinbean's avatar

@Xanger Change your route definition to have the filename passed as a route parameter rather than reading it from the query string.

Xanger's avatar

Hi @martinbean how can I do?

Do I have to remove the "input:get" and do as I did with width and height?

I try with:

Route::get('thumbs/{imgw}x{imgh}/{urlimg}', function ($imgw,$imgh,$urlimg)
{
    $width = $imgw;
    $height = $imgh;
    $src = $urlimg;
36864's avatar

If that's the only change you make, you'll end up with a url that looks something like

/thumbs/133x124/upload/news/news_110cfe3247815927e0624116215f5066.jpg

Depending on how you want your url structure to look like, you might want to use only the file name as a parameter and add the path prefix in your route handler.

Xanger's avatar

@36864 The important thing is to remove "?src=" the url structure is not important to me, but I did not understand how to do it...

Cronix's avatar

Personally I'd get a S3 bucket and use it as a cdn for your images, and scale them all there when uploaded. Yes, its $. But resizing images on the fly takes more cpu/ram, and if your site gets pretty busy, you might run into capacity issues depending on how beefy your server is. This is possible of course, it's just not really a good idea.

Please or to participate in this conversation.