-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertSvgToPng.ps1
54 lines (46 loc) · 1.4 KB
/
convertSvgToPng.ps1
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
param(
$source = "icon.svg",
$destination = "icon.png",
$width = $null,
$height = $null)
$ErrorActionPreference = "Stop"
[Environment]::CurrentDirectory = $PWD
$inkscape = "C:\Program Files\Inkscape\inkscape.exe"
$source = [System.IO.Path]::GetFullPath($source)
$destination = [System.IO.Path]::GetFullPath($destination)
$destinationDirectoryPath = [System.IO.Path]::GetDirectoryName($destination)
# validate parameters
if (-not (Test-Path -Path $inkscape))
{
throw "Please install Inkscape (https://inkscape.org/).";
}
if (-not (Test-Path -Path $source))
{
throw "Source file not found.";
}
# clean up
if (Test-Path -Path $destination)
{
Remove-Item -Path $destination -Force
}
if (-not (Test-Path -Path $destinationDirectoryPath))
{
New-Item -Path "$destinationDirectoryPath" -ItemType Directory
}
# generate PNG icon with transparent background
if ($width -ne $null -and $height -ne $null)
{
& $inkscape -z "$source" --export-png="$destination" --export-width $width --export-height $height --export-background-opacity=0 | Out-String
}
elseif ($width -ne $null)
{
& $inkscape -z "$source" --export-png="$destination" --export-width $width --export-background-opacity=0 | Out-String
}
elseif ($height -ne $null)
{
& $inkscape -z "$source" --export-png="$destination" --export-height $height --export-background-opacity=0 | Out-String
}
else
{
throw "Please specify either desired width or height or both.";
}