-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertICO2Image.psm1
More file actions
63 lines (54 loc) · 1.75 KB
/
ConvertICO2Image.psm1
File metadata and controls
63 lines (54 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<#
.SYNOPSIS
Converts a given ICO file to a either a PNG, JPG, BMP or Tiff File
.PARAMETER files
The directory where your .ico file is stored (defaults to the Current Working Directory)
.PARAMETER Formats
The format you would like to convert to. Can input more than one format if you want multiple copies.
.EXAMPLE
PS C:\> Convert-ICO2Image
.EXAMPLE
PS C:\> Convert-ICO2Image -files c:\ico_conversion -Format Png
.EXAMPLE
PS C:\> Convert-ICO2Image -files "C:\ico_conversion" -Formats Bmp,Jpeg,Png,Tiff,Gif
#>
function Convert-ICO2Image
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $false)]
$files = (Get-Item .\).FullName,
[Parameter(Mandatory = $false)]
[ValidateNotNull()]
[ValidateSet('Png','Jpeg','Bmp','Tiff','Gif')]
[string[]]$Formats = 'Png'
)
begin
{
Add-Type -AssemblyName system.drawing
}
process
{
foreach ($Format in $Formats)
{
$files = Get-ChildItem $files -Filter *.ico -file -Recurse |
foreach-object {
$Source = $_.FullName
$test = [System.IO.Path]::GetDirectoryName($source)
$base = $_.BaseName + ".$Format"
$basedir = $test + "\" + $base
$imageFormat = "System.Drawing.Imaging.ImageFormat" -as [type]
$image = [drawing.image]::FromFile($Source)
# Create a new image
$NewImage = [System.Drawing.Bitmap]::new($Image.Width, $Image.Height)
$NewImage.SetResolution($Image.HorizontalResolution, $Image.VerticalResolution)
# Add graphics based on the new image
$Graphics = [System.Drawing.Graphics]::FromImage($NewImage)
$Graphics.DrawImageUnscaled($image, 0, 0) # Add the contents of $image
# Now save the $NewImage
$NewImage.Save($basedir, $imageFormat::$Format)
}
}
}
}