Jump to content

Unexpected Behavior of image field.


peterpp
 Share

Recommended Posts

My code is as below

<?php
$header_image = $page->header_image;
if( !empty($header_image) ){
    $head_image = $header_image->first();
    $img = $head_image->size(940,627);
}

The code was working fine for 2 months.

But now i am having issue with this image field. Sometimes image loads sometimes it doesnt loads. Somtime it throws arror sometimes gives broken image.

Plz help

Regards,

Pravin

Edited by Adam Kiss
Fixed code formatting
Link to comment
Share on other sites

What error odes come up? Has the image changed? Server configuration?

Make sure that the error is not something on the client side (e.g. AdBlock blocking, firewal, Browsercache).

From the ProcessWire perspective, you might want to manually delete the cache (/site/assets/cache) and remove all variations of this image. To do this, go to the folder of the image (under /site/assets/files/<pageid>/, just look at the URL of the image to get the ID) and then remove all files from this image (e.g. image.jpg, image.100x0.jpg image.940x627.jpg,...).

Link to comment
Share on other sites

I'd guess your image field is multiple cause of the ->first()

It, the field, should be name then header_images

I think empty() isn't worth using here

if( $page->header_images->count ){
    $head_image = $page->header_images->first();
    $img = $head_image->size(940,627);
    ...
} else {
    // no image
}

If there were a issue with image field many would have this problem, but it's not.

  • Like 1
Link to comment
Share on other sites

What error odes come up? Has the image changed? Server configuration?

Make sure that the error is not something on the client side (e.g. AdBlock blocking, firewal, Browsercache).

From the ProcessWire perspective, you might want to manually delete the cache (/site/assets/cache) and remove all variations of this image. To do this, go to the folder of the image (under /site/assets/files/<pageid>/, just look at the URL of the image to get the ID) and then remove all files from this image (e.g. image.jpg, image.100x0.jpg image.940x627.jpg,...).

Thanx for you quick reply. This didn't worked for me...

Link to comment
Share on other sites

This is the error I get:

Fatal error
: Exception: Method Pageimages::size does not exist or is not callable in this context (in /xxx/wire/core/Wire.php line 320) #0 /xxxx/site/templates/calendar/calendar-top.inc(31): Wire->__call('size', Array) #1 /xxxx/site/templates/calendar/calendar-top.inc(31): Pageimages->size(185, 140) #2 /xxx/site/templates/home.php(5): include('/home/xx/...') #3 /xxx/wire/core/TemplateFile.php(140): require('/home/xxxx/...') #4 [internal function]: TemplateFile->___render() #5 /xxx/core/Wire.php(359): call_user_func_array(Array, Array) #6 /home/xxx/wire/core/Wire.php(317): Wire->runHooks('render', Array) #7 /xxx/wire/modules/PageRender.module(337): Wire->__call('render', Array) #8 /home/xxx/wire/modules/PageRender.module(337): TemplateFile->render() #9 [ in
/home/xxxxxx/index.php
on line
216
 
Regards
Pravin
Link to comment
Share on other sites

It's expected behaviour of the Pageimages (array)

You're trying to set a pixel size to an array of images. Pageimages (array of images) doesn't have a size, because it is an array.

You need to go 1 step deeper, get the image, then set the size to an individual image.

If you run the code below, what does it say ?

if ($page->header_image instanceof Pageimage) {
    echo "(Pageimage) - Single image, yeah, you can use size.<br>";
} elseif ($page->header_image instanceof Pageimages) {
    echo "(Pageimages) - Array of images, can't use size.<br>";
}
  • Like 2
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...