Jump to content

image size: fatal error


reems
 Share

Recommended Posts

Hi,

I have the following php lines in a template:

$top10 = $pages->find("template=hotel, top10>0,sort=-top10");
foreach($top10 as $top) 
  {
  echo "<li><a href='{$top->url}'>{$top->title}</a></li>";
  $image = $top->foto_upload->first();
  $thumb = $image->size(100, 100); 
// if($image) echo "<img src='$image->url'>";
  }

The last (for the moment commented) line works fine and shows one image but too big. Before showing the image I want to resize it.

But the line "$thumb =$image->size(100, 100);" throws the following error:

Fatal error: Exception: Method Pagefile::size does not exist or is not callable in this context (in /home/travelinlu/domains/travelinluxury.nl/public_html/wire/core/Wire.php line 320) in /home/travelinlu/domains/travelinluxury.nl/public_html/index.php on line 216

Reading the forum on such errors gives me no clear solution. Most of the time the answer is, that the function is called on an image array, but in this case (after using first() ) it is clear just one image I want to resize.

"foto_upload" is (afcourse) an Image field and I use PW 2.4.

Anyone with a solution??

Thanks,

Reems 

Link to comment
Share on other sites

How stupid of me, indeed, it was still a File field instead of an Image field. Thanks Apeisa.

Now it works as it should be.

But, Kongondo, could you explain your solution: $image->of(true); ?

I can't find it in the API and I'm curious what is does.

Btw, that did not work, I got this error:

"Method Pageimage::of does not exist or is not callable in this context"

Thanks!

Link to comment
Share on other sites

By default, output will be formatted according filters you may have defined with the field. If you are modifying the values of a page's custom fields, you will need to call $page->setOutputFormatting(false) before doing so. This turns off output formatting, which ensures that saved values don't already have runtime formatters applied to them. ProcessWire will throw an error if you attempt to save formatted fields.

See the cheatsheet. Usually you use this to change values on pages and save them through the API.

I don´t know why to use it here. Kongondo might explain that ;)

  • Like 1
Link to comment
Share on other sites

Thanks guys for stepping in!

Setting ->of(), and the image field will always be an array, no matter what the maxFiles is set to.

( was maybe better if Ryan wasn't that nice for the single image and it would always be an array )

Slapped my forehand a few times with that one ;)

Yep, what Martijn said or read here from the Reiska himself :-)

https://processwire.com/talk/topic/163-images-and-thumbnails/?p=1160

This hidden gem is truly a hidden gem ;)

  • Like 1
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...