Skip to content

Pageimage variations with different extensions not detected without same-extension variant #2048

Open
@trk

Description

@trk

Current Behavior

When checking for image variations, ProcessWire only detects variations with different extensions (like .webp or .avif) if there exists at least one variation with the same extension as the original image.

For example:

  • If original image is image.jpg:
    • ✅ Detected: Having both image.0x260.jpg and image.0x260.webp
    • ❌ Not Detected: Having only image.0x260.webp without image.0x260.jpg
    • ❌ Not Detected: Having only image.-custom-suffix.webp

Expected Behavior

ProcessWire should be able to detect all variations regardless of their file extension, allowing for:

  • Direct creation of .webp/.avif variations without requiring a same-extension variant
  • Custom suffixes with different extensions to be recognized as valid variations

Example

With an original image image.jpg, these variations should be directly detectable:

We can use something like (for get all variations):

$pathinfo = pathinfo($image->filename);
 
// can you also add this function to WireFileTools::glob(string|array $pattern)                   
$getVariations = function(string $pattern): array {
    // Try with GLOB_BRACE first
    $variations = glob($pattern, GLOB_NOSORT | GLOB_BRACE);
    // If no results with GLOB_BRACE, try without it
    if (!$variations) {
        $variations = glob($pattern, GLOB_NOSORT) ?: [];
    }
    return $variations;
};

// get suffix variations
bd($getVariations("{$pathinfo['dirname']}/{$pathinfo['filename']}.[cpd0-9-]*.*"));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions