Jump to content
picarica

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

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

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
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 😕

Share this post


Link to post
Share on other sites
13 hours ago, picarica said:

but i still wonder why getimagesize didnt worked

system file path, NOT url 

  • Like 2

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Marvin
      Hello, excuse me
      I'm new at processwire, i want to ask about a master detail system (Inheritance system) using a processwire. Can we create a Inheritance table using a processwire, and how we create it? Thank you for the help
    • By picarica
      so hello there i have fiel field type i have lots of stuff there, and also an image i can easily get image from that field using
                                                        
      $options = array('quality' => 85, 'upscaling' => true, 'cropping' => 'north', 'sharpening' => 'medium'); $word = ".png"; // Test if string contains the word foreach($childgames->subor_hry as $file) { if(strpos($file, $word) !== false){ /* $imger = $file->size(473, 266, $options); */ echo $file; /* echo $file->url; */ } } so i get the fiel i tried invoking size on it like the commented out part and it doesnt work i get error Oh snizzle… Error:     Exception: Method Pagefile::size does not exist or is not callable in this context (in
      what am i doing wrong? can you guys help me by all logic this should work
    • By Max Esnée
      Hi,
      When I upload a large(ish) SVG (≈120ko in this case) into an image field, it tends to get stuck at 100% and block the whole website. If I force refresh the admin page, the svg has not been uploaded. The file is correctly copied into the assets folder though. Other svg tends to be uploaded fine albeit I've noticed that pages containing svg images in the admin are very slow to load generally. Other pages using the same template but with jpeg or png images are much faster to load.
      I get the following error in the JS console:

      I develop locally using MAMP on macOS and I'm using Firefox. I'm using the last ProcessWire version (3.0.165).
      I also tested in Chrome and got the same error.
    • By Marvin
      Hi,
      I'm still new at processwire, i want to ask, i was create a website with sign in system, but i want to add a access roles/permission for each user at my website. For now, i just can create a login user without any permission and the user data became as a pages in my processwire.
      Here i attach my code for login
      <?php $note = $note2 = $hidden =""; if($input->get->id == "logout") { $session->remove('login_id'); } if($input->post->submit) { $email = $sanitizer->email($input->post->email); $pass = $sanitizer->text($input->post->pass); $result = $pages->find("email=$email, text_1=$pass"); if(!$email || !$pass) { $note = "Data belum lengkap"; } else { if($result->count > 0) { $session->login_id = "$result"; $hidden = "style = 'diplay:none'"; $url=$pages->get("/files/")->httpUrl; header("Location:$url"); die(); } else { $note = "Akun tidak ditemukan"; } } } ?> And this code for login form
      <div class="frow-container"> <div class="frow centered mt-50"> <div class="col-md-1-3"> <div class="box p-40 shadow-light"> <h2 class="mb-20 text-center" <?=$hidden?>>Database Partitur<br>GII HIT</h2> <form method="post" <?=$hidden?>> <label>Username <input type="text" name="email"></label> <label>Password <input type="password" name="pass"></label> <input type="submit" name="submit" value="Masuk"> </form> <p class="notif"><?=$note;?></p> <div class="text-center"><?=$note2;?></div> </div> </div> </div> </div> Just for remember, my user data now is a pages, and i cannot give any permission to user data.
      Thank you very much for help.
    • By Marvin
      Hello, my name Marvin, i want to ask something. I'm new at processwire, and still learn it, i try yo showing an image, at a table, the image was show, but i can't resize the image
      please HELP
      Here i attach, my code belor
      <?php $num = 1; foreach($pages->get("/files/")->children as $child) { $current = $child === $page ? " class='current'" : ''; $result = $child->images; // $result->width(900); // $result->height(100); foreach($result as $items){ foreach($pages->get($child->name)->files as $file) { // $file = $child->files; // echo $file->name; echo "<tr><td>".$num++.".</td><td>".$child->title."</td><td>".$child->text_1."</td><td>".$child->text_2."</td><td>".$child->text_3."</td><td><a href='".$file->httpUrl."'>".$file->name."</a></td><td><img src='".$items->url."'></td></tr>"; } } } ?>  
×
×
  • Create New...