This convenient bookmarklet automatically adjusts an SVG file loaded directly in the browser to be centered in a square viewBox, adds a configurable margin around the content, and initiates a quick download of the modified SVG.
- Open a standalone SVG file directly in your browser.
- Click the bookmarklet.
- When prompted, enter your desired margin in pixels.
- The modified SVG will be downloaded automatically, named after your original file.
bookmarklet.js
: Readable source code of the bookmarklet.bookmarklet.min.js
: Minified bookmarklet ready to drag onto your bookmark bar.
Because GitHub doesn't allow direct dragging from README files, follow these simple steps to manually add the bookmarklet:
- Copy the minified JavaScript code from
bookmarklet.min.js
. - In your browser, right-click on your bookmarks bar and choose "Add Page" (or use "Add bookmark").
- Paste the copied JavaScript code directly into the "URL" field.
- Name it (e.g., "SVG Square-Fit π") and save the bookmark.
- Margin is prompted dynamically at runtime.