maybe you could try something like this:
<?php
$img = Image::make(file_get_contents('http://images.boomsbeat.com/data/images/full/979/justin-bieber-2013-3226-hdwallfan-jpg.jpg' ));
$img->encode('png');
?>
{!! $img !!}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I can display an image from a route with the following:
Route::get('/', function()
{
$img = Image::make(file_get_contents('http://images.boomsbeat.com/data/images/full/979/justin-bieber-2013-3226-hdwallfan-jpg.jpg'));
// create response and add encoded image data
$response = Response::make($img->encode('png'));
// set content-type
$response->header('Content-Type', 'image/png');
// output
return $response;
});
But I can't get an image to display from a blade view. The following gives me a blank screen:
<?php
$img = Image::make(file_get_contents('http://images.boomsbeat.com/data/images/full/979/justin-bieber-2013-3226-hdwallfan-jpg.jpg'));
// create response and add encoded image data
$response = Response::make($img->encode('png'));
// set content-type
$response->header('Content-Type', 'image/png');
// output
return $response;
?>
I want to watermark images on the fly. I could save them with watermarks, but that means I'll loose flexibility because the user won't be able to change the watermark without every single image being altered.
I've also tried something similar by passing the image through the controller but that also didn't work :(
@ldiebold Yeah, you want to use ->response() to return an image from a route or controller action.
You don’t want to be resizing images on the fly within your scripts, because then the visitor has to wait for that operation to complete before the page can continue rendering. If it’s say, a 5 megapixel image being resized, then that’s going to take a couple of seconds, and if you have more than one, then your users are going to be waiting a long time for a page to render. It’s also going to put unnecessary strain on your web server.
Please or to participate in this conversation.