Get Image Width Spatie Libary for Laravel

362 Views Asked by At

I would like to have the image width output so that I can use certain classes at a certain width.

With the current code snippet it throws me an error: Unable to init from given url

Can someone help me?

@foreach($imgs as $img)
                @php

                        $imageInstance = Spatie\Image\Image::load($img->getFullUrl());
                        $imageWidth = $imageInstance->getWidth();

                @endphp
            <div id="grid-item" class="grid-item grid-item--width2"><img src="{{$img->getFullUrl()}}" class="img-fluid " {{$imageWidth}}></div>
            @endforeach
1

There are 1 best solutions below

0
On BEST ANSWER
@foreach($imgs as $img)
            @php

                    $imageInstance = Spatie\Image\Image::load($img->getPath());
                    $imageWidth = $imageInstance->getWidth();

            @endphp
        <div id="grid-item" class="grid-item grid-item--width2"><img src="{{$img->getFullUrl()}}" class="img-fluid " {{$imageWidth}}></div>
        @endforeach