@@ -4,31 +4,49 @@ function Convert-ImageToHtml
4
4
. SYNOPSIS
5
5
This function can be used to convert an image file into an HTML IMG tag with an image
6
6
embedded in the SRC so that an external image file doesn't have to be referenced.
7
- . PARAMETER $Infile
7
+ . PARAMETER $ImageFile
8
8
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 .
11
11
. 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
13
17
. NOTES
14
18
Author: Scott Sutherland (@_nullbind)
15
19
#>
16
20
17
21
[CmdletBinding ()]
18
22
Param (
19
23
[Parameter (Mandatory = $true ,
24
+ ValueFromPipeline = $true ,
25
+ ValueFromPipelineByPropertyName = $true ,
20
26
HelpMessage = ' The image file path.' )]
21
27
[string ]$ImageFile ,
22
28
23
29
[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
26
32
)
27
33
28
34
29
35
Process {
30
36
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
+
32
50
# Read image file
33
51
$ImageBytes = [System.IO.File ]::ReadAllBytes(" $ImageFile " )
34
52
0 commit comments