Click to show script, save it as a .ps1 and adjust paths as needed
Copy to Clipboard
# Call script using:
# powershell.exe -File "AddLogo.ps1" -Filename "C:\Tools\Scripts\File.jpg" -Suffix "-MySuffix" -TemplateFile "C:\Tools\Scripts\Batch\Template.png"
param([String]$Filename="", [String]$Suffix="", [String]$TemplateFile="")
Add-Type -AssemblyName 'System.Drawing'
if ( $psise ){
$SourceImage = "C:\Tools\Scripts\Batch\test4.jpg"
$Suffix = "-Honor"
$TemplateFile = "C:\Tools\Scripts\Batch\Template-HH.png"
}else{
$SourceImage = $Filename
if ( $Suffix.length -lt 0 ){ $Suffix = "-New" }
}
$SpacingLeft = [Math]::Round( 50 * ( $Image.width / 2400 ) )
$SpacingRight = $SpacingLeft
$SpacingTop = [Math]::Round( 50 * ( $Image.height / 2051 ) )
$SpacingBottom = [Math]::Round( 277 * ( $Image.height / 2051 ) )
Write-Host "Loading picture: $($SourceImage)"
$Image = [System.Drawing.Bitmap]::FromFile($SourceImage)
$FinalImagePath = ( ( $SourceImage | Split-Path -Parent ) + '\' + [System.IO.Path]::GetFileNameWithoutExtension($SourceImage) + $Suffix + ".jpg" )
$Template = [System.Drawing.Bitmap]::FromFile($TemplateFile)
$TemplateResized = New-Object System.Drawing.Bitmap( ( $Image.width + $SpacingLeft + $SpacingRight ).ToInt32($null) , ( $Image.Height + $SpacingTop + $SpacingBottom ).ToInt32($null) )
$TemplateGraphics = [System.Drawing.Graphics]::FromImage($TemplateResized)
$TemplateGraphics.DrawImage($Template, 0, 0, ($Image.width + $SpacingLeft + $SpacingRight ) , ( $Image.Height + $SpacingTop + $SpacingBottom ))
$FinalCanvas = [System.Drawing.Bitmap]::new( ($Image.width + $SpacingLeft + $SpacingRight ).ToInt32($null) , ( $Image.Height + $SpacingTop + $SpacingBottom ).ToInt32($null) )
$g = [System.drawing.graphics]::FromImage($FinalCanvas)
$g.Clear([System.Drawing.Color]::Black)
# Put it there
#$g.DrawImage($Image, $SpacingLeft, $SpacingTop)
#$g.DrawImage($Image, [System.Drawing.Point]::new($SpacingLeft, $SpacingTop) , [System.Drawing.Rectangle]::new(0,0,100,100) )
$g.DrawImage($Image, [System.Drawing.Rectangle]::new($SpacingLeft,$SpacingTop,$Image.width,$Image.height) , [System.Drawing.Rectangle]::new(0,0,$Image.width,$Image.height) , [System.Drawing.GraphicsUnit]::Pixel)
$g.DrawImage($TemplateResized, 0, 0)
#$g.DrawString("test")
# Save it
Write-Host "Saving picture: $FinalImagePath"
$FinalCanvas.Save($FinalImagePath, [System.Drawing.Imaging.ImageFormat]::Jpeg)
|