Jump to content

Recommended Posts

Posted

any idea why my image resizing/cropping doesn't work?

everything works fine on the site when I use (in a foreach loop):

                $main_image = $item->image_field;

but as soon as I try to crop the images or resize…

                $main_image = $item->image_field->width(300);
	            $main_image = $item->image_field->size(300, 300);

When I use either of these two lines (not both together obviously) I get an Uncaught Error: Call to a member function width() on null

The image field is set to single image, not to array. Apparently the error is triggered upon rendering, because I don't even have to output the images to trigger the error. Also enabled cache on the page that uses this specific field but that didn't do it either.

I'm currently working on several PW projects on my MAMP-localhost, resizing works for the other project (blank profile) but not this one described here (regular profile).

Any advice? thanks for help!

Posted

OK here I go answering my own question.

The image field might not be an array, but the pages that have this field are. So once there is a page on which that field is of empty value, the rendering process, as far as I can tell, dies.

So when I use

	if ($item->image_field) {$main_image = $item->image_field->width(300);}

it works fine.

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.
×
×
  • Create New...