Jump to content

[SOLVED] getimagesize doesnt work when fed image from repeat field?


picarica
 Share

Recommended Posts

so i am trying to fetch dimensions of image using getimagesize() but it returns nothing, at least i think so, i want to feed it to data attribute, bit its emtpy, i tried feeding it the image directly or just image->url

here is my source code


 

foreach($page->repeat_body as $r_body) {
 /* other code here*/
                        if ($r_body->gallery_check == 1) {

                        echo "<div class='my-gallery' id='grid-gallery' itemscope itemtype='http://schema.org/ImageGallery'>";
                            foreach($r_body->image as $image) {
                                $options = array('quality' => 80, 'upscaling' => true, 'cropping' => 'north', 'sharpening'=>'medium');
                                $thumb = $image->size(400, 400, $options);
                                $large = $image->size(1280, 0, $options);
                                list($width, $height) = getimagesize($image->url);
                                echo "
                                <figure itemprop='associatedMedia' itemscope itemtype='http://schema.org/ImageObject'>
                                  <a href='$large->url' itemprop='contentUrl' data-size='$widthx$height' data-index='0'>
                                    <img src='$thumb->url' height='$height' width='$width' itemprop='thumbnail' alt='Beach'>
                                  </a>
                                </figure>";
                            }
                        echo "</div>";
                        }
/* other code here*/
}

now, the images are outputted correctly, i can open then and browse them

Link to comment
Share on other sites

It needs the image filename and not a url. The php function getimagesize works for files in the systems filesystem. But why do you not use the $image->width and $image->height properties when you already have the $pageimage object. Why invoking an additional call to an external function when all you want to know is already there?

Link to comment
Share on other sites

47 minutes ago, horst said:

It needs the image filename and not a url. The php function getimagesize works for files in the systems filesystem. But why do you not use the $image->width and $image->height properties when you already have the $pageimage object. Why invoking an additional call to an external function when all you want to know is already there?

oh well i tried googling 'processwire how to get images dimension' but didnt found anything, thanks for the tip i'll try it out

Link to comment
Share on other sites

2 minutes ago, horst said:

Processwire site top right, the menu DOCS -> API reference | and there you have to look for pageimage(s)

https://processwire.com/api/ref/

 

oh found it ! https://processwire.com/api/ref/pageimage/

thanks for the help, i didnt knew it was called pageimage :D. ill mark this as solved, it works perfectly, but i still wonder why getimagesize didnt worked ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...