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

khaled-elmahdi's avatar

Image resize by URL

Hello,

I have a laravel app that allow the user to upload images. Images are stored in the public directory. Something like this: www.domain.com/storage/4/properties/41117/1289c67b34c151de66538022168d0895ab534456.jpg www.domain.com/storage/2/properties/41327/1289c63b34c151de66538022168d0895ab534456.jpg

Is there a way to allow resizing the image by adding something like this to the end of the URL ?width=100&height=100

I would like to serve the images directly if no query strings attached, and send the URL to a controller to resize it using intervention/image if we have a query string - if possible.

Thank you in advance

0 likes
11 replies
khaled-elmahdi's avatar

Thanks @ohffs for the reply but I am not sure how to set it up!

I've added it to my project using: composer require league/glide

in my route.php I added this:

$server = League\Glide\ServerFactory::create([
    'source'         => public_path(),
    'cache'          => public_path('cache'),
    'max_image_size' => 1024 * 1024,
]);

Route::get('storage/{path}', function ($server, $path) {
    dd($path);
    $server->outputImage($path, $_GET);
})->where('path', '.*');

Saying so, the images are served directly and dd($path) is not firing.

Is there something I can do here to make it work?

khaled-elmahdi's avatar

Still the same,

Route::get('storage/{path}', function ($server, $path) {
    dd($path);
    $server->outputImage($path, $_GET);
})->where('path', '.*');

The dd($path) is not firing at all!

ohffs's avatar

Are the files inside your public/ directory? If so they will get served directly without hitting your routes if the url matches a 'real' file.

khaled-elmahdi's avatar

Ok,

It seems that the route file doesn't run if the file physically exist. I moved my outside the public directory and everything is working fine now.

Thanks everyone for the help.

ohffs's avatar

@khaled-elmahdi yay - glad it's working :-) Where-abouts are you in 'sunny' Scotland btw?

ohffs's avatar

@khaled-elmahdi I've never been either - I keep seeing messages from them after the event on twitter and thinking 'oh, aye, meant to go to that...' ;-) Maybe see you there sometime if either of us manges it :-)

Please or to participate in this conversation.