This script is very similar to the Collage Maker of the previous post. Instead of a folder full of images this script will randomly place a single image around in the Collage Image. Underlying is the same process but you get quite different results.
 
Here are a couple samples from this script –
 
ImageCollage1
 
And another with fewer, larger images –
 
ImageCollage2
 
I’m only going to review the couple of changes from the previous post.
 
Instead of using the FolderBrowserDialog control to select a folder I used the OpenFileDialog control to allow for file selection. The Browse Button calls the selectFiles Function for selecting the input file. After the image is selected the inputPicture Function is called to display the image in the form.
 

# Browse Input Button
$buttonBrowse = New-Object System.Windows.Forms.Button
$buttonBrowse.Location = "560, 80"
$buttonBrowse.Size = "75, 23"
$buttonBrowse.ForeColor = "MediumBlue" 
$buttonBrowse.Text = "Browse"
$buttonBrowse.add_Click({selectFiles})
$mainForm.Controls.Add($buttonBrowse)

function selectFiles {
	$selectForm = New-Object System.Windows.Forms.OpenFileDialog
	$selectForm.Filter = "All Files (*.*)|*.*"
	$selectForm.InitialDirectory = ".\"
	$selectForm.Title = "Select a File to Process"
	$getKey = $selectForm.ShowDialog()
	If ($getKey -eq "OK") {
            $textBoxIn.Text = $selectForm.FileName
            $completeLabel.Text = "      "
            InputPicture($selectForm.FileName)
	}
} # End SelectFile

 
SelectFile
 
Since only a single image is being used to generate the collage I wanted to display it as a preview. The input image is displayed with a PictureBox, the same as is used to show the final assembled collage. I used the Zoom SizeMode to fully fit the image within the PictureBox boundaries.
 

# Input PictureBox
$inputPicture = New-Object System.Windows.Forms.PictureBox
$inputPicture.Location = "90, 200"
$inputPicture.ClientSize = "320, 200"
$inputPicture.BackColor = "Black"
$inputPicture.SizeMode = "Zoom"
$mainForm.Controls.Add($inputPicture)

Function InputPicture {
    $file = (Get-Item $selectForm.FileName)
    $image = [System.Drawing.Image]::Fromfile($file)
    $inputPicture.Image = $image
}

 
The interface is a bit different from the previous post, mainly to accommodate two PictureBoxes.
 
ImageRandomizer
 
Download the complete script here – SingleImageCollage.ps1
 
Updated 7/5/14 – Added additional output images sizes and changed image size text parser from SubString to Split.
 

Advertisements