Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripting Existing SVGs with ConvertTo-PSSVG #53

Closed
StartAutomating opened this issue Oct 14, 2022 · 0 comments · Fixed by #55
Closed

Scripting Existing SVGs with ConvertTo-PSSVG #53

StartAutomating opened this issue Oct 14, 2022 · 0 comments · Fixed by #55
Assignees
Labels
enhancement New feature or request Post Issues that should become posts

Comments

@StartAutomating
Copy link
Owner

StartAutomating commented Oct 14, 2022

ConvertTo-PSSVG

PSSVG would be much more useful if it could easily convert any SVG off of the internet into a PSSVG file.

So, as of PSSVG 0.2.4, you can ConvertTo-PSSVG

What it does

ConvertTo-PSSVG takes an SVG from a file, url, string, or xml document and converts it into a PSSVG script.

For example, if I download the feather icon for anchor and then run

ConvertTo-PSSVG Anchor.svg

It will output:

=<SVG> -width '24' -height '24' -viewBox '0 0 24 24' -fill 'none' -stroke 'currentColor' -strokewidth '2' -strokelinecap 'round' -strokelinejoin 'round' -class 'feather feather-anchor' -Content @(
    =<SVG.circle> -cx '12' -cy '5' -r '3'
    =<SVG.line> -x1 '12' -y1 '22' -x2 '12' -y2 '8'
    =<SVG.path> -d 'M5 12H2a10 10 0 0 0 20 0h-3'
)

How it works

This is actually fairly trivial.

First we get the XML form of the input, then we:

  1. Go thru to the first node
  2. Replace text nodes with their text.
  3. Find the appropriate command
  4. Replace attributes with parameters (if found)
  5. Replace child nodes recursively (effectively goto step 1).

For bonus points, we indent.

What we can do with this

Being able to ConvertTo-PSSVG gives you an easy way to integrate any existing design into your scripts. This can help, say, establish a visual leitmotif.

Hope this Helps

@StartAutomating StartAutomating added the enhancement New feature or request label Oct 14, 2022
@StartAutomating StartAutomating self-assigned this Oct 14, 2022
StartAutomating pushed a commit that referenced this issue Oct 14, 2022
@StartAutomating StartAutomating changed the title ConvertTo-PSSVG Scripting Existing SVGs with ConvertTo-PSSVG Oct 15, 2022
@StartAutomating StartAutomating added enhancement New feature or request Post Issues that should become posts and removed enhancement New feature or request labels Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Post Issues that should become posts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant