Add Timestamp to Images

ImageMagick needs to be installed, including legacy tools, and in the path

Takes files with the format yyyyMMdd.jpg in the current directory, and adds a stamp to the bottom-right corner in the MMM dd yyyy format. Creates a new file named “stamped.yyyyMMdd.jpg”

$MagickExe = "magick"

Get-ChildItem -Filter *.jpg | Sort-Object -Property Name | ForEach-Object {
	$BaseFileName = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
	[ref]$PicDate = [DateTime](Get-Date)

	$Provider = [System.Globalization.CultureInfo]::InvariantCulture
	$Style = [System.Globalization.DateTimeStyles]::None
	if ([DateTime]::TryParseExact($BaseFileName, "yyyyMMdd", $Provider, $Style, $PicDate)) {
		$FormattedDate = $PicDate.Value.ToString("MMM dd yyyy")
		$Arguments = "convert" `
			+ " -verbose" `
			+ " $($_.Name)" `
			+ " -gravity SouthEast" `
			+ " -font Arial" `
			+ " -pointsize 81" `
			+ " -fill white" `
			+ " -stroke black" `
			+ " -annotate +81+81" `
			+ " `"$FormattedDate`"" `
			+ " stamped.$BaseFileName.jpg"
		Start-Process -FilePath $MagickExe -ArgumentList "$Arguments" -Wait -NoNewWindow
	}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s