1

I can show resized image with this code inside route,

Route::get('/create', function(){
    $img = Image::make('assets/tes.jpg')->resize(200, 200);
    return $img->response('jpg');
}

But how I can return resized image from Controler to View ?

Here is my Controller

publc function show($id){
$image = /*What code here ? resize assets/tes.jpg to 200x200*/
return view('some', compact('image'));
}

Here is my View some.blade.php

<img src="$image">

or should I resize on upload and save it, instead of resize on the fly ?

Thanks, any help appreciated.

1
  • 1
    You could always use Intervention’s own image cache if you’re wanting to resize thumbnails on the fly. But the best approach is to resize on upload, and then stream an appropriately-sized thumbnail in your web pages. Commented Oct 8, 2015 at 10:13

1 Answer 1

2

should I re-size on upload and save it, instead of re-size on the fly

Yes, If you are worried about the split seconds (but noticeable time) it takes to re-size and render images on the fly then you are better off with re-sizing on upload and saving various sizes.

Coming to how to display re-sized image in the view:

You can simply specify your route URL:

I am using public_path("/assets/$img") because I assume your images are located in public\assets

Route:

Route::get('/assets/{img}',function($img){
    return \Image::make(public_path("/assets/$img"))->resize(200, 200)->response('jpg');
});

You can even play with the sizes:

Route::get('/assets/{img}/{h}/{w}',function($img, $h=200, $w=200){
        return \Image::make(public_path("/assets/$img"))->resize($h, $w)->response('jpg');
 });

Later in the View:

<img src="{!! url('assets', ['tes.jpg']) !}}">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.