Jump to content

[solved] Image Variations not recreated after cropping?


bernhard
 Share

Recommended Posts

This seems to be a fundamental feature so I must be missing something...

I have a RockPageBuilder element called "Gallery". I don't think that it matters or RockPageBuilder has anything to do with it, but maybe I'm wrong, so I mention it for completeness.

In that gallery block the client can upload images and in my code I create thumbnails from that images and show a gallery like this:

pPlAdqK.png

Images are output like this:

$images->eq(0)->maxSize(800,800)->webp->url

Today the client contacted me, that she cropped one image, but the image does not update on the website...

I thought I forget the cache busting timestamp, but that's in place and not the issue.

Looking into the variations of the image I clearly see the issue:

HTDQ0sW.png

Image #0 and #2 are the newly cropped images. All others are outdated.

Any idea why ProcessWire does not recreate those variations?

I have done some research and found one old issue by myself that has been closed by @netcarver and I found this module by @Robin S

But I'm wondering... am I missing something obvious? Why would I need an additional module to make sure that ProcessWire resets image variations when the underlying original image has been cropped? That makes no sense to me?

Thank you very much for your help!

Link to comment
Share on other sites

I'm not sure if it's a solution to your issue, but I have this hook in every site (see the referenced issues for background):

// Instead of rebuilding image variations, remove them and they'll be rebuilt when next requested
// Fix for: https://github.com/processwire/processwire-issues/issues/1301
// Also see: https://github.com/processwire/processwire-issues/issues/1277
$wire->addHookBefore('Pageimage::rebuildVariations', function(HookEvent $event) {
	/** @var Pageimage $pageimage */
	$pageimage = $event->object;
	$event->replace = true;
	$pageimage->removeVariations();
	// Return expected output to avoid errors
	$event->return =  [
		'rebuilt' => [],
		'skipped' => [],
		'reasons' => [],
		'errors' => [],
	];
});

It's only safe to do this if you do not allow image variations to be directly inserted into RTE fields. More info in this comment: https://github.com/processwire/processwire-issues/issues/1301#issuecomment-893957331

  • Like 1
Link to comment
Share on other sites

  • bernhard changed the title to [solved] Image Variations not recreated after cropping?

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