public/Convert-FootballFixtureMediaFile.ps1

function Convert-FootballFixtureMediaFile {
    <#
        .EXAMPLE
            Convert-FootballFixtureMediaFile -Competition esp-laliga -Date 2025-04-13 -Content match -Path C:\sportsmonk
         
    #>

    [CmdletBinding()]
    param(  

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Competition,

        [Parameter(Mandatory=$true)]
        [ValidateSet('corners','goals','match','outcomes')]
        [string]$Content,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Date,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Path

    )
    process{

        $ErrorActionPreference = 'Stop'

        try {

            if ($Content -eq 'outcomes') {

                $PathToUse = "$Path\fixture-artifact\working-set\$Competition\$Date"

            }
            else {

                $PathToUse = "$Path\fixture-artifact\working-set\$Competition\$Date\$Content"

            }

            # Test path to media files exist
            $PathToUseExists = Test-Path -Path $PathToUse

            # Set destination
            $StoryPath = "$Path\fixture-artifact\instagram\story\$Content"

            # try to create the folder
            New-Directory -Path $StoryPath

            # Test if folder exists
            $StoryPathExits = Test-Path -Path $StoryPath

            if ($PathToUseExists -and $StoryPathExits) {
                
                Set-Location -Path $PathToUse
                $FilesToProcess = Get-ChildItem -Path  $PathToUse -File -Filter '*.png' -ErrorAction Stop

                foreach ($File in $FilesToProcess) {

                    $CurrentName = $($File.FullName)
                    $NewName = $CurrentName.Replace('.png','.jpg')

                    # third party application to convert to jpg
                    magick $CurrentName $NewName

                    # Get the file name
                    $FileName = $NewName.Split('\')[-1]

                    # Set destination file path and name
                    $FilePath = "$StoryPath\$FileName"
                    
                    # This gets the dominant blue color from the image and uses it as the background
                    magick $CurrentName -resize 1080x1920 -background "rgb(25,48,114)" -gravity center -extent 1080x1920 $FilePath

                } # foreach

            } # if

        }
        catch {

            throw "$($MyInvocation.MyCommand.Name): $_.Exception.Message"

        } # try catch

    } # process

} # function