reems Posted June 1, 2014 Share Posted June 1, 2014 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 More sharing options...
kongondo Posted June 1, 2014 Share Posted June 1, 2014 Try $image->of(true); just before resizing... Link to comment Share on other sites More sharing options...
apeisa Posted June 1, 2014 Share Posted June 1, 2014 I think you have file field instead of image field. 3 Link to comment Share on other sites More sharing options...
kongondo Posted June 1, 2014 Share Posted June 1, 2014 Good catch Antti! Link to comment Share on other sites More sharing options...
reems Posted June 2, 2014 Author Share Posted June 2, 2014 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 More sharing options...
arjen Posted June 2, 2014 Share Posted June 2, 2014 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 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted June 2, 2014 Share Posted June 2, 2014 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 ) 3 Link to comment Share on other sites More sharing options...
kongondo Posted June 2, 2014 Share Posted June 2, 2014 Yep, what Martijn said or read here from the Reiska himself https://processwire.com/talk/topic/163-images-and-thumbnails/?p=1160 1 Link to comment Share on other sites More sharing options...
arjen Posted June 2, 2014 Share Posted June 2, 2014 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 1 Link to comment Share on other sites More sharing options...
reems Posted June 5, 2014 Author Share Posted June 5, 2014 Thank you all. I will keep on learning and enjoy it Reems Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now