Search code examples
powershellvips

Powershell Integration with ImageMagick / VIPS


I am trying to iterate through a list of files on disk, run a command for each file using VIPS / ImageMagick, then output a file and move it to to a different directory. I can't seem to get the commands to work together.

Why are the variables $_Basefile not working in this command?

Individual Commands for VIPS

vips tiffsave input_file.tif output_file.tiff --args[...]

PowerShell Commands

ls | %{vips tiffsave $_BaseFile.tif $_BaseFile.tiff --compression jpeg --Q=90 --whateverelse }

Update: The answer marked correctly below worked. Thumbs up for the well explained reasons why it didn't work! The proper command is:

GCI -File -Filter "*.tif" | %{vips tiffsave "$($_.FullName)" "$($_.BaseName).tiff" --compression jpeg --Q=90}

Solution

    • To learn which methods/properties are exposed through the pipeline you should issue an Get-ChildItem -File|Get-Member or short ls -File|gm
    • You'll see it's $_.FullName and $_.BaseName you need

    So try:

    GCI -File -Filter "*.tif" | %{vips tiffsave "$($_.FullName)" "$($_.BaseName).tiff" --compression jpeg --Q=90}
    

    ls, dir, gci are all aliases of the Get-ChildItem cmdlet