Jump to content

image size issue


eze102
 Share

Recommended Posts

Hi - can someone explain to me why I can't modify image size with the following code?

                                        <?
                                        foreach($page->call_to_action as $cta) {
                                            $count++;
                                            $class = ($count == 2) ? "one_half last" : "one_half";
                                            $img = $cta->image->size(300,300);
                                            echo "<div class='{$class}'>
                                                <a href='{$cta->call_to_action_url}' class='over'>
                                                        <span>{$cta->overlay_title}</span>
                                                            <p>{$cta->overlay_description}</p>
                                                    </a>
                                                    <a href='{$cta->call_to_action_url}'><img src='{$img->url}'</a>
                                            </div>";
                                        }
                                        ?>
Link to comment
Share on other sites

Sorry, I don't get what you are asking for?!

Can you explain a bit more what your code does or does not and what you want to be the result?

Also I'm not sure, but the original image URL in the a-tag, shouldn't it be:

<a href='{$cta->call_to_action->url}'
                              ^^      = -> instead of _ ??
Link to comment
Share on other sites

Yes, I'm sorry. That was not clear!

I created a repeater field called "call_to_action" with a few subfields, including "overlay_title" , "overlay_description" , "image" , and "call_to_action_url".

I wanted to iterate over the "call_to_action" fields and output them, which is working; I also wanted to resize the image in the image field, but that isn't working... even though I did:

 $img = $cta->image->size(300,300);
Link to comment
Share on other sites

Aha! :)

You need to debug what your $cta->image really holds.

  • [ ] check if the fieldname is correct (image or images or other?)
  • [ ] check if the image field is set to single-mode, what is
  • [ ] put a line into your code to inspect the value (see *1)

*1)

foreach($page->call_to_action as $cta) {
    $count++;
    $class = ($count == 2) ? "one_half last" : "one_half";
    $img = $cta->image->size(300,300);

// debug $img:
echo "<pre>\n\n";
var_dump($img);
die('RIP :: ' . __FILE__ . ':' . __LINE__);

    echo "<div class='{$class}'>
        <a href='{$cta->call_to_action_url}' class='over'>
        	<span>{$cta->overlay_title}</span>
            <p>{$cta->overlay_description}</p>
        </a>
        <a href='{$cta->call_to_action_url}'><img src='{$img->url}' /></a>
    </div>";
}

BTW: in your code the img tag is unclosed (/>), and your code does not check if an image is really set for each repeater item. Or is the image field set to be required in the template?

  • Like 2
Link to comment
Share on other sites

Thank you! I still can't seem to access the size property of the image though.

Fieldname is correct and image is in single mode.

And when I add your debug code, I get like 5000 lines of output in the browser that I can't understand (I'm not very experienced with PHP). The code does not just stop the file and show the img value, it shows tons of lines of code...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...