Jump to content

Pageimage::rebuildVariations() Question


cosmicsafari
 Share

Recommended Posts

Hi all,

Just wondering if someone with a bit more PW knowledge than me could give a run down of what this method actually does and how its achieved.

I get that it rebuilds image variations but based on what settings?

If I wanted to rebuild all the websites image variations but at say a reduced image quality can this be set somewhere globally that this method would take into account?

For some context I have built a fairly simple module to delete all the image variations connected to any FieldtypeImage which is being used on the website, for the most part this works quite well. As I was quite happy with how that turned out I figured I would give the module another option to rebuild the images also. So there would be a 'Remove' and 'Rebuild' button on the modules config page.

The idea being that I could use this tool to delete all the image variations, update some global settings then regenerate them all but currently it doesn't appear to do that.

I assume this is either because my codes borked or im misunderstanding something fundamental about how rebuildVariations() works.

Link to comment
Share on other sites

I think the best explanation is directly above that method:

Quote

    /**
     * Rebuilds variations of this image
     *
     * By default, this excludes crops and images with suffixes, but can be overridden with the `$mode` and `$suffix` arguments.
     *
     * **Options for $mode argument**
     *
     * - `0` (int): Rebuild only non-suffix, non-crop variations, and those w/suffix specified in $suffix argument. ($suffix is INCLUSION list)
     * - `1` (int): Rebuild all non-suffix variations, and those w/suffix specifed in $suffix argument. ($suffix is INCLUSION list)
     * - `2` (int): Rebuild all variations, except those with suffix specified in $suffix argument. ($suffix is EXCLUSION list)
     * - `3` (int): Rebuild only variations specified in the $suffix argument. ($suffix is ONLY-INCLUSION list)
     * - `4` (int): Rebuild only non-proportional, non-crop variations (variations that specify both width and height)
     *
     * Mode 0 is the only truly safe mode, as in any other mode there are possibilities that the resulting
     * rebuild of the variation may not be exactly what was intended. The issues with other modes primarily
     * arise when the suffix means something about the technical details of the produced image, or when
     * rebuilding variations that include crops from an original image that has since changed dimensions or crops.
     *
     * #pw-group-variations
     *
     * @param int $mode See the options for $mode argument above (default=0).
     * @param array $suffix Optional argument to specify suffixes to include or exclude (according to $mode).
     * @param array $options See $options for `Pageimage::size()` for details.
     * @return array Returns an associative array with with the following indexes:
     *  - `rebuilt` (array): Names of files that were rebuilt.
     *  - `skipped` (array): Names of files that were skipped.
     *  - `errors` (array): Names of files that had errors.
     *  - `reasons` (array): Reasons why files were skipped or had errors, associative array indexed by file name.
     *
     */

So, as I understand this, it tries to rebuild variations. But limited variations, 0 = without suffixes, without crops, etc. (read on above).

But to know which variations are belong to an image, the variations have to exist! (It gets all variations and then try to determine how they were build, what seems to be simple for mode = 0, but becomes more and more special and indefferent with higher modes).

HTH ?

  • Like 2
Link to comment
Share on other sites

5 minutes ago, horst said:

I think the best explanation is directly above that method:

So, as I understand this, it tries to rebuild variations. But limited variations, 0 = without suffixes, without crops, etc. (read on above).

But to know which variations are belong to an image, the variations have to exist! (It gets all variations and then try to determine how they were build, what seems to be simple for mode = 0, but becomes more and more special and indefferent with higher modes).

HTH ?

So if im understanding that correctly then its doesn't create them anew like $page->image->width() would, rather it attempts to recreate them using what already exists?

That definitely would explain the results I was seeing, as it did work if some variations existed already but not if it was just the originals.

Link to comment
Share on other sites

38 minutes ago, cosmicsafari said:

That definitely would explain the results I was seeing, as it did work if some variations existed already but not if it was just the originals.

Yes, it iterates the page's assets directory, checks every file if it is a variation of the current image and, if yes, recreates it with the constraints encoded in the variation's filename.

  • Like 2
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

×
×
  • Create New...