Jump to content
thuijzer

Save image focus

Recommended Posts

First I like to say that the new(ish) focus function for images is really great!

But I can't seem to save focus via the API. Does anyone know how to do this?

I tried all methods described in Pageimage.php:

$member->avatar->focus($top, $left);
$member->save();
$member->avatar->focus($top . ' ' . $left);
$member->save();
$member->avatar->focus([$top, $left]);
$member->save();

But whatever I try, the focus is never updated/saved.

 

Extra note: in de database the field "filedata" becomes empty when I use the methods described above.

Share this post


Link to post
Share on other sites

Just doing this in my basic-page template works fine:

$page->of(false);
foreach($page->images as $img) {
	$img->focus("10%", "10%");
}
$page->save();
$page->of(true);

 

Share this post


Link to post
Share on other sites
30 minutes ago, Soma said:

Just doing this in my basic-page template works fine:


$page->of(false);
foreach($page->images as $img) {
	$img->focus("10%", "10%");
}
$page->save();
$page->of(true);

 

 

Yes. This is indeed how I thought it should work.

I just discovered that it only works when I create a new image.
For example:
 

// this works:
$member->of(false);
$member->avatar = $filename; // avatar becomes a \ProcessWire\PageImages
$member->avatar->first->focus(10, 10);
$member->save();
$member->of(true);

// this does not work:
$member->of(false);
$member->avatar->first->focus(50, 50); // avatar already is a \ProcessWire\PageImages
$member->save();
$member->of(true);

By the way: $member is a \ProcessWire\User but I don't think this should be the problem.

So I guess I'm doing something else wrong.

Thank you for your reply!

Share this post


Link to post
Share on other sites

Make sure you work with a Pageimage and not Pageimages or something else. It works perfectly.

You do 

$member->avatar->first->focus(10, 10);

but before you did

$member->avatar->focus(10, 10);

Share this post


Link to post
Share on other sites

Yes I made sure I'm working with a Pageimage, but I still don't get it.

What I see:

  • The focus of an existing image is updated in the model (avatar field).
  • The "changes" property is updated to notify that "filedata" is changed.
  • When I save the model it returns 'true'.
  • When I debug all database queries I see the model's modified date is updated, but the new focus is never stored.
  • When I change the function PageFiles::resetTrackChanges so that nothing gets reset, the new focus is stored in the database.

So somewhere along the way the "changes" property is reset for the avatar field, but I can't figure out when and why.

Going to dive deeper into this 🤔

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...