Garrett
Garrett

Reputation: 649

Pull images and file owner through PowerShell to ImageMagick 'Montage'

I am trying to build a PowerShell script that will pull jpgs from particular directories recursively and run them through ImageMagick montage to create a Contact Sheet with the filenames as the labels. As of now, my $filename code is broken, as it only provides the last file's name and labels for all the images with the same filename.

Currently I have:

foreach ($dailyPhotoBay in $dailyServerPath)
{
$dailyImage = Get-ChildItem -Path $dailyPhotoBay -Include *.jpg -Recurse | Where-Object {$_.PSParentPath -like "*Output*"}

foreach ($image in $dailyImage)
{
    $fileName = [System.IO.Path]::GetFileNameWithoutExtension($dailyImage)
    }
    echo $fileName

    montage -verbose -label $fileName -pointsize 20 -background '#FFFFFF' -tile '5x40' -fill 'black' -define jpeg:size=600x780 -geometry 600x780+40+150 -quality 90  -auto-orient $dailyImage.FullName D:\Contact_Sheet\Sheet.jpg
}

With this code all images are pulled and the contact sheet looks correct, except all the images are labeled the same - the name of the very last image.

As always, any help is appreciated.

Thanks!

Upvotes: 0

Views: 115

Answers (1)

fmw42
fmw42

Reputation: 53081

In ImageMagick, use %f to show the filename with suffix in montage or %t to show the filename (without suffix). ImageMagick should strip the paths. So create a variable $filenames that contains a list of files with different names.suffix with or without the paths.

For example:

convert logo: /Users/fred/desktop/logo.png

To get the filename.suffx:

montage -label "%f" /Users/fred/desktop/logo.png montage1.png

enter image description here

Or to get just the filename without suffix

montage -label "%t" /Users/fred/desktop/logo.png montage2.png

enter image description here

So for your montage do the following if you want the filename with suffix to show:

montage -verbose -label "%f" -pointsize 20 -background '#FFFFFF' -tile '5x40' -fill 'black' -define jpeg:size=600x780 -geometry 600x780+40+150 -quality 90  -auto-orient $dailyImage D:\Contact_Sheet\Sheet.jpg


or do the following if you want the filename without suffix:

montage -verbose -label "%t" -pointsize 20 -background '#FFFFFF' -tile '5x40' -fill 'black' -define jpeg:size=600x780 -geometry 600x780+40+150 -quality 90  -auto-orient $dailyImage D:\Contact_Sheet\Sheet.jpg


Sorry I do not know PowerShell. So I cannot tell you how to get the list of filenames from your directory.

See http://www.imagemagick.org/script/escape.php http://www.imagemagick.org/Usage/montage/#label

Upvotes: 1

Related Questions