chcs Posted 20 hours ago Posted 20 hours ago (edited) According to the documentation that I have seen the following code should work, but it throws an exception. What's wrong? // copy from one image object to another $targetImage = $objTarget->add($srcImg->filename); if ($targetImage) { $aFocus = $srcImg->focus(); $top = $srcImg['top']; $left = $srcImg['left']; $targetImage->focus($top, $left); } When I execute this code it throws the following exeption: Method Pageimages::focus does not exist or is not callable in this contextProcessWire\Pageimages Object ( [count] => 1 [page] => /events/monthly-event/editor/ [field] => ev_banner [url] => /site/assets/files/20678/ [path] => C:/xampp/htdocs/membership/site/assets/files/20678/ [items] => Array ( [cityhall-2.jpg] => Array ( [url] => /site/assets/files/20678/cityhall-2.jpg [filename] => C:/xampp/htdocs/membership/site/assets/files/20678/cityhall-2.jpg [filesize] => 11612 [description] => foo [tags] => [created] => 2025-12-12 16:08:55 [modified] => 2025-12-12 16:08:55 [created_users_id] => 41 [modified_users_id] => 41 [filemtime] => 2025-12-12 16:08:55 [width] => 300 [height] => 168 [suffix] => [focus] => top=74.5%,left=74.5%,zoom=0% ) ) ) Edited 20 hours ago by chcs
bernhard Posted 12 hours ago Posted 12 hours ago 7 hours ago, chcs said: Method Pageimages::focus does not exist or is not callable in this contextProcessWire\Pageimages Object Your $targetImage is not a Pageimage but a Pageimages object. That's the case when output formatting is off or you request the image via $page->getUnformatted('myimagefield') or similar. To get the Pageimage (singular) object from a Pageimages object you can do $images->first() or ->last() etc.; see https://processwire.com/api/ref/pageimages/ and as it extends WireArray also https://processwire.com/api/ref/wire-array/ 1
chcs Posted 8 hours ago Author Posted 8 hours ago $objTarget->add() returns a Pageimages object, so to access the added image one must get Pageimages->first() to get a Pageimage object
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