Ad

Laravel Image Intervention Unable To Init From Given Url

- 1 answer

Good evening, i hosted a Laravel project and found some bug. First of all, here is my code in my controller:

        $request->file('FotoHT')->storeAs('FotoHT',$filenameToStore); //this is to safe

        $path = asset('storage/app/FotoHT/'. $filenameToStore);

         $width = Image::make($path)->width();
         $height = Image::make($path)->height();

I save a picture, and it works but when i try using Image::make($path)->width(); it give me the wrong url. It give me

https://myweb/public/storage/app/FotoHT/_MG_9549_1578913993.jpg

while the image should be accessed from

 https://myweb/storage/app/FotoHT/_MG_9549_1578913993.jpg

Can anyone give me a help/solution?

Ad

Answer

You need to save the image encode to the public path

$fieldFile = $request->file('FotoHT');
$image = Image::make($fieldFile)->width(); 
Storage::disk('public')->put("FotoHT/".$filenameToStore, (string) $image->encode());
Ad
source: stackoverflow.com
Ad