Skip to content

Commit 5034b27

Browse files
authored
Update Convert-ImageToHtml.ps1
1 parent 0091e4b commit 5034b27

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

Convert-ImageToHtml.ps1

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,49 @@ function Convert-ImageToHtml
44
.SYNOPSIS
55
This function can be used to convert an image file into an HTML IMG tag with an image
66
embedded in the SRC so that an external image file doesn't have to be referenced.
7-
.PARAMETER $Infile
7+
.PARAMETER $ImageFile
88
The image file path.
9-
.PARAMETER $Outfile
10-
The html output file path.
9+
.PARAMETER $MakeHtml
10+
An HTML file will be created using the same name as the image file.
1111
.EXAMPLE
12-
PS C:\> Convert-CsvToPsDt -Infile c:\temp\serverinfo.csv -Outfile c:\temp\createmydatatable.ps1
12+
PS C:\> Convert-ImageToHtml -$ImageFile c:\temp\picture.png -Verbose
13+
.EXAMPLE
14+
PS C:\> Get-ChildItem *.png | select fullname | Convert-ImageToHtml -Verbose
15+
.EXAMPLE
16+
PS C:\> Get-ChildItem *.png | select fullname | Convert-ImageToHtml -Verbose -MakeHtml
1317
.NOTES
1418
Author: Scott Sutherland (@_nullbind)
1519
#>
1620

1721
[CmdletBinding()]
1822
Param(
1923
[Parameter(Mandatory = $true,
24+
ValueFromPipeline = $true,
25+
ValueFromPipelineByPropertyName = $true,
2026
HelpMessage = 'The image file path.')]
2127
[string]$ImageFile,
2228

2329
[Parameter(Mandatory = $false,
24-
HelpMessage = 'The html output file path.')]
25-
[string]$HtmlFile = ".\image.html"
30+
HelpMessage = 'An HTML file will be created using the same name as the image file.')]
31+
[switch]$MakeHtml
2632
)
2733

2834

2935
Process {
3036

31-
try {
37+
try {
38+
39+
# Process for common parameter names if pipeline is used
40+
if($PSCmdlet.MyInvocation.ExpectingInput){
41+
$CheckFullName = $_ | gm | where name -like "fullname"
42+
if($CheckFullName){
43+
$ImageFile = $_.fullname
44+
}
45+
}
46+
47+
# Verbose info
48+
Write-Verbose "Processing $ImageFile"
49+
3250
# Read image file
3351
$ImageBytes = [System.IO.File]::ReadAllBytes("$ImageFile")
3452

0 commit comments

Comments
 (0)