Return Response Image in Laravel 7

3

I'm trying to create a mini random image generator, as a start I've tried :

Route::get('/img/UoJb9wl.png','Image@random');

All I did is to return this

return '<img src="/assets/fe/img/welcome.jpeg" alt="Smiley face" width="200">';

Then, I tested on the live site :

I see the image loaded if I go to the URL

https://www.bunlongheng.com/img/UoJb9wl.png

If I imported on a site like JSFiddle like this

<img src="https://www.bunlongheng.com/img/UoJb9wl.png">

I can't see it.

Why ?


Edit

Try #2

return env('APP_URL').'/assets/fe/img/welcome.jpeg';

I return image path now

But I still nothing rendering in my JSFiddle still

<img src="https://www.bunlongheng.com/img/UoJb9wl.png">

Share
Improve this question
4
  • May be this is happen for header's content_type, header('Content-Type: image/png'); your header's content_type may be not a image type, what's your controller code? – Espresso Apr 14 at 21:32
  • 3
    On your controller you can return an image like this method return response($img_path)->header('Content-type','image/png'); – Espresso Apr 14 at 21:34
  • @EsTeAa I tried that, and now the page is not showing anything. i.imgur.com/DoAWTjU.png – cyb3rZ Apr 15 at 0:23
  • It return path now https://www.bunlongheng.com/img/UoJb9wl.png Result : i.imgur.com/PZgNRyD.png – cyb3rZ Apr 15 at 0:43

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

flutter websocket connection issue