
One of the challenges I faced with this project was when using large datasets of 100K+ nodes, the process of exporting and opening an SVG with that many objects is a little taxing even for the best image editing software.
In the end, I decided to write a small PowerShell script that would import the SVG, and using Inkscapes exe, you can convert this into a PNG. Pretty awesome.
The PowerShell script
The script’s premise is to import the SVG, calculate the dimensions/aspect ratio of the vector image, and use this to output a correctly sized bitmap representation. Simple.
param(
[string]$sourceSvg = 'E:\Gephi\Map.svg',
[string]$inkscapeExec = 'C:\Program Files\Inkscape\bin\inkscape.exe',
[double]$scale = 1.0
)
# Check if source SVG file exists
if (-not (Test-Path $sourceSvg)) {
Write-Host "File $sourceSvg not found."
exit
}
# Extracting SVG dimensions
[xml]$svgContent = Get-Content -Path $sourceSvg
$width = [double]($svgContent.svg.width -replace "px", "")
$height = [double]($svgContent.svg.height -replace "px", "")
# Scaling dimensions
$scaledWidth = [int]($width * $scale)
$scaledHeight = [int]($height * $scale)
# Define target PNG name
$targetPng = [System.IO.Path]::ChangeExtension($sourceSvg, 'png')
Write-Host "Converting $sourceSvg (W: $width, H: $height) to $targetPng with scaled dimensions W: $scaledWidth, H: $scaledHeight..."
$command = "& `"$inkscapeExec`" --export-filename=`"$targetPng`" -w $scaledWidth -h $scaledHeight `"$sourceSvg`""
Invoke-Expression $command
-
You must be signed in to star a gist -
You must be signed in to fork a gist
-
Save pferreirafabricio/97c1c68057e406ff0f98840659973f0d to your computer and use it in GitHub Desktop.
🖼 Convert an image to a Base64 string with PowerShell
The AsByteStream parameter was introduced in Windows PowerShell 6.0 | |
If your PowerShell version (run `(Get-Host).Version` to find out) is lower than 6 then use the version for Powershell 5.1: | |
For Powershell 5.1 | |
[] []::ToBase64String(( Raw Encoding Byte)) | |
For Powershell 6+ | |
[] []::ToBase64String(( Raw AsByteStream)) | |
Captions
Captions
Add a one-line explanation of what this file represents
Contents
Description | Neofetch-Ausgabe eines Beispielrechners mit einem technischen Stand von etwa 2020-2021 unter Windows 11. Hier in Windows PowerShell. Die Werte können als Gradmesser bzw. Vergleich für Leistungen von Rechnern in 5, 10 oder gar 20 Jahren dienen. Neofetch output of a sample computer with a technical status of around 2020-2021 under Windows 11, here in Windows PowerShell. The values can serve as an indicator or comparison for the performance of computers in 5, 10 or even 20 years. |
Date | |
Source |
|
Author |
|
![]() | This work includes material that may be protected as a trademark in some jurisdictions. If you want to use it, you have to ensure that you have the legal right to do so and that you do not infringe any trademark rights. See our general disclaimer. This tag does not indicate the copyright status of the attached work. |
![]() | This file is licensed under the Expat License, sometimes known as the MIT License: |
![]() | This file is licensed under the Expat License, sometimes known as the MIT License: |
![]() | This file is licensed under the Expat License, sometimes known as the MIT License: |
File usage on Commons
There are no pages that use this file.
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 18:08, 9 December 2023 | ![]() | 7,680 × 4,080 | PantheraLeo1359531 | Uploaded a work by * Neofetch: Dylan Araps <br /> * Windows Terminal/Windows PowerShell: Microsoft Corporation from * Neofetch in Windows Terminal (CMD) und Windows PowerShell unter Windows 11 23H2 with UploadWizard |
You cannot overwrite this file.
Metadata
This file contains additional information such as Exif metadata which may have been added by the digital camera, scanner, or software program used to create or digitize it. If the file has been modified from its original state, some details such as the timestamp may not fully reflect those of the original file. The timestamp is only as accurate as the clock in the camera, and it may be completely wrong.
Horizontal resolution | 188.96 dpc |
---|---|
Vertical resolution | 188.96 dpc |