Jump to content

remove specific variation


darrenc
 Share

Recommended Posts

Is there a way to delete a specific variation of an image without simply nuking every single variation?

I've been working with processwire for a while and I'm surprised this isn't possible given the things you can do with different arrays of PW objects.

Here's what I've tried:

$image->size(200, 200);
$image->size(201, 201);
$image->size(202, 202);
$image->size(203, 203);

$image->removeVariations("width=201"); // nope
$image->getVariations()->find("width=201"); // nope
$image->getVariations()->get("width=201"); // nope

foreach ($image->getVariations() as $variation) {
	if ($variation->width == 201) $image->removeVariations($variation); // nope
	if ($variation->width == 201) $variations->delete($variation); // nope
	if ($variation->width == 201) $image->delete($variation); // nope
	if ($variation->width == 201) $variations->remove($variation); // nope
	if ($variation->width == 201) $image->remove($variation); // nope
}

 

Link to comment
Share on other sites

4 hours ago, darrenc said:
$image->removeVariations("width=201"); // nope

PageImage::removeVariations takes an associative array of options as its argument, which in turn is passed on to PageImageVariations::remove and PageImageVariations::find. The docs for the latter say (irrelevant parts snipped):

	/**
	 * @param array $options Optional, one or more options in an associative array of the following:
	 * 	- `width` (int): only variations with given width will be returned
	 * 	- `height` (int): only variations with given height will be returned
	 * 	- `width>=` (int): only variations with width greater than or equal to given will be returned
	 * 	- `height>=` (int): only variations with height greater than or equal to given will be returned
	 * 	- `width<=` (int): only variations with width less than or equal to given will be returned
	 * 	- `height<=` (int): only variations with height less than or equal to given will be returned
	 * 	- `suffix` (string): only variations having the given suffix will be returned
	 *  - `suffixes` (array): only variations having one of the given suffixes will be returned
	 *  - `noSuffix` (string): exclude variations having this suffix
	 *  - `noSuffixes` (array): exclude variations having any of these suffixes
	 *  - `name` (string): only variations containing this text in filename will be returned (case insensitive)
	 *  - `noName` (string): only variations NOT containing this text in filename will be returned (case insensitive)
	 *  - `regexName` (string): only variations that match this PCRE regex will be returned
     */

So ["width" => "201"] should work (untested though).

  • Like 1
Link to comment
Share on other sites

20 hours ago, BitPoet said:

So ["width" => "201"] should work (untested though).

Okay fair enough I haven't tested this yet either but lets say it works... i would presumably get the same reference doing it the longer way:

foreach ($image->getVariations() as $variation) {
	if ($variation->width == 201) $image->removeVariations($variation); // nope
	

if i have $variation as the reference to the exact same file, how do i remove it from the variations-stack for the image?

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