|
| 1 | +--- |
| 2 | + |
| 3 | +title: Rasterizing SVGs with obs powershell |
| 4 | +author: StartAutomating |
| 5 | +sourceURL: https://github.com/StartAutomating/obs-powershell/issues/42 |
| 6 | +--- |
| 7 | +SVG is an amazing graphics format and a great web standard. |
| 8 | + |
| 9 | +Unfortunately, it's also a standard that's not fully implemented by many imaging tools. |
| 10 | + |
| 11 | +If, for instance, you want to rasterize an SVG with ImageMagik, go ahead and kiss your symbols goodbye and forget even using CSS classes. Many imaging apps can't handle large chunks of the SVG standard, which leads to omitted text and elements. |
| 12 | + |
| 13 | +And don't even get me started on _animated_ SVGs. |
| 14 | + |
| 15 | +Luckily, OBS has a browser source, and lets us easily capture an SVG as an image or a video _exactly as it would render in Chrome_. |
| 16 | + |
| 17 | +Let's cover images first. |
| 18 | + |
| 19 | +Because SVGs are scalable, and raster images are not, step one is to get our dimensions right. |
| 20 | + |
| 21 | +SVGs have a Viewbox, which contains the width and height they'll want to render at. |
| 22 | + |
| 23 | +Create a browser source of that width / height, then pipe it to Save-OBSScreen. |
| 24 | + |
| 25 | +~~~PowerShell |
| 26 | +Add-OBSBrowserSource -Uri https://4bitcss.com/Batman.svg -Width 640 -Height 240 | |
| 27 | + Save-OBSSourceScreenshot -ImageFormat png -ImageFilePath (Join-Path $pwd "Batman.png") |
| 28 | +~~~ |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +Because of the Object Pipeline in PowerShell, we don't even need to pass along the -ImageHeight and -ImageWidth to Save-OBSSourceScreenshot (the browser source has an .ImageHeight and .ImageWidth property). |
| 33 | + |
| 34 | +It gets even better. |
| 35 | + |
| 36 | +The file that Save-OBSSourceScreenshot returns packs a little bit of extra info: |
| 37 | + |
| 38 | +* What source generated it |
| 39 | +* What scene it was in |
| 40 | + |
| 41 | +Which means we can actually just take a snapshot and remove it: |
| 42 | + |
| 43 | +~~~PowerShell |
| 44 | +Add-OBSBrowserSource -Uri https://4bitcss.com/Batman.svg -Width 640 -Height 240 | |
| 45 | + Save-OBSSourceScreenshot -ImageFormat png -ImageFilePath (Join-Path $pwd "Batman.png") | |
| 46 | + Remove-OBSSceneItem |
| 47 | +~~~ |
| 48 | + |
| 49 | +Hope this Helps! |
0 commit comments