Jump to content

[SOLVED] Cannot resize image


Marvin
 Share

Recommended Posts

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>";
                }
              }
            }
          ?>

 

Edited by Marvin
I'm solved my problem
Link to comment
Share on other sites

Hey @Marvin,

Welcome to ProcessWire and the forums. It looks like your are dealing with multiple images. You need to resize them individually in your code. Something like this:

<?php
$num = 1;
foreach($pages->get("/files/")->children as $child) {
    $current = $child === $page ? " class='current'" : '';
    $images = $child->images;
    // $images->width(900);
    // $images->height(100);
    foreach($images as $image){
    foreach($pages->get($child->name)->files as $file) {
        // $file = $child->files;
        // echo $file->name;
        // ---> RESIZE SINGLE IMAGE <---
    //   $imageThumb = $image->size(200,200);
        $imageThumb = $image->width(900);

        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='".$imageThumb->url."'></td></tr>";
    }
    }
}
?>

See the docs here:

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

Link to comment
Share on other sites

Hello @kongondo
Thanks for reply, i have been try your suggestion, but the size not change, should i use get->filename() to change it?
I mean should i get a filename first and then i set width and height using `$image->width([value])` and `$image->height([value])`?

Thank you

Link to comment
Share on other sites

Hi @Marvin,

Sorry, I missed your post. It's difficult to tell what's going on because I am not sure what type of fields you are using, e.g. are they actual images of images in file fields. Maybe try the below outside your code, just to test. This assumes you have a field called 'images' and it allows multiple images.

// Example of outputting a thumbnail gallery of Pageimage objects
foreach($page->images as $image) {
  // $image and $thumb are both Pageimage objects
  $thumb = $image->size(200, 200);
  echo "<a href='$image->url'>";
  echo "<img src='$thumb->url' alt='$image->description' />";
  echo "</a>";
}

Do you get the correct output with resized images? Do you get any errors? If so, which ones?

Link to comment
Share on other sites

  • 2 weeks later...

Hi @kongondo

It's ok, sorry for my late reply too, i had job to do, lately. I have field for files like for .docx or .pdf, and i have a field for images, but when i try to add a image, from a form the image seems not add to the images field, but that was add to a files field.

And for your code your suggest, is it place inside foreach iteration or make new foreach iteration?

For resize a image i don't get any error message, just when i try to reload my page, its showing the result the image cannot resize width or height either, like image i attach below. Thank you

image.thumb.png.65bf1af02be2843da285956d89f4899a.png

Link to comment
Share on other sites

Hi @kongondo,

I solved it, i can change a width and height of my image using a css, but now i have one more issue, that is, when i upload an image and a file at the same time, there just a file save it to the processwire, but for image i have to save it manually from back-end. Any suggestion for it? Thank you very much

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...