Jump to content

Save image focus


thuijzer
 Share

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.

Link to comment
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);

 

Link to comment
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!

Link to comment
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);
Link to comment
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 ?

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...