### Install svg-outline-stroke with Yarn
Source: https://github.com/elrumordelaluz/outline-stroke/blob/master/README.md
Installs the svg-outline-stroke package using the Yarn package manager. This is the primary method to add the library to your project.
```zsh
yarn add svg-outline-stroke
```
--------------------------------
### Usage: Outline SVG from Buffer Input
Source: https://github.com/elrumordelaluz/outline-stroke/blob/master/README.md
Shows how to outline an SVG file read as a Buffer. This example reads an SVG from './source.svg', outlines it using svg-outline-stroke, and then writes the result to './dest.svg'.
```javascript
const fs = require('fs')
const outlineStroke = require('svg-outline-stroke')
fs.readFile('./source.svg', (err, data) => {
if (err) throw err
outlineStroke(data).then(outlined => {
fs.writeFile('./dest.svg', outlined, err => {
if (err) throw err
console.log('yup, outlined!')
})
})
})
```
--------------------------------
### Optimize SVG Quality with Larger Dimensions using Node.js
Source: https://context7.com/elrumordelaluz/outline-stroke/llms.txt
Demonstrates how scaling up the input SVG's dimensions improves the quality of the traced output. Larger input dimensions result in more accurate path traces and better detail preservation. This example compares the output of a small SVG with a large SVG, showing that the high-quality version produces more path points. Requires the 'svg-outline-stroke' library.
```javascript
const outlineStroke = require('svg-outline-stroke')
// Low quality input (small dimensions)
const smallSVG = `
`
// High quality input (larger dimensions, same viewBox ratio)
const largeSVG = `
`
async function compareQuality() {
try {
const lowQuality = await outlineStroke(smallSVG)
const highQuality = await outlineStroke(largeSVG)
console.log('Low quality path length:', lowQuality.length)
console.log('High quality path length:', highQuality.length)
// High quality version will have more path points and smoother curves
return { lowQuality, highQuality }
} catch (err) {
console.error('Quality comparison error:', err)
}
}
compareQuality()
```
--------------------------------
### Params: Customizing Outline Trace with Fill Color
Source: https://github.com/elrumordelaluz/outline-stroke/blob/master/README.md
Illustrates how to pass custom parameters to the outlineStroke function to modify the tracing process. This example sets the 'fill' color of the output paths to '#bada55'.
```javascript
outlineStroke(strokedSVG, { color: '#bada55' }).then(outlined => {
console.log(outlined, 'Outlined SVG with #bada55 `fill` color')
})
```
--------------------------------
### Outline SVG Stroke with Buffer Input (Node.js)
Source: https://context7.com/elrumordelaluz/outline-stroke/llms.txt
Processes SVG data provided as a Buffer, suitable for file system operations or streaming. The function returns a Promise that resolves to the outlined SVG string. This example demonstrates reading from a file and writing the result to another file.
```javascript
const fs = require('fs')
const outlineStroke = require('svg-outline-stroke')
// Reading from file
fs.readFile('./source.svg', (err, data) => {
if (err) {
console.error('File read error:', err)
return
}
outlineStroke(data)
.then(outlined => {
fs.writeFile('./outlined.svg', outlined, err => {
if (err) {
console.error('File write error:', err)
return
}
console.log('SVG successfully outlined and saved!')
})
})
.catch(err => {
console.error('Outline conversion failed:', err)
})
})
```
--------------------------------
### Outline SVG Stroke with String Input (Node.js)
Source: https://context7.com/elrumordelaluz/outline-stroke/llms.txt
Converts an SVG string with stroked paths into an SVG string with filled path outlines. This function is asynchronous and returns a Promise that resolves to the outlined SVG data. Ensure the 'svg-outline-stroke' library is installed.
```javascript
const outlineStroke = require('svg-outline-stroke')
// Basic usage with string input
const strokedSVG = `
`
outlineStroke(strokedSVG)
.then(outlined => {
console.log(outlined)
// Returns SVG string with filled paths instead of strokes
})
.catch(err => {
console.error('Conversion failed:', err)
})
```
--------------------------------
### Async/Await Usage
Source: https://context7.com/elrumordelaluz/outline-stroke/llms.txt
Demonstrates how to use the outlineStroke function with modern async/await syntax for cleaner error handling and sequential operations.
```APIDOC
## Async/Await Usage
### Description
Leverages async/await for a more readable and manageable way to handle the asynchronous SVG outline conversion process, especially when dealing with file I/O.
### Method
Asynchronous Function (returns a Promise)
### Parameters
See `outlineStroke(input, params)` documentation.
### Request Example
```javascript
const fs = require('fs').promises
const outlineStroke = require('svg-outline-stroke')
async function convertSVG(inputPath, outputPath) {
try {
const svgBuffer = await fs.readFile(inputPath)
const outlined = await outlineStroke(svgBuffer, {
color: '#000000',
background: 'transparent'
})
await fs.writeFile(outputPath, outlined)
console.log(`Successfully converted ${inputPath} to ${outputPath}`)
return outlined
} catch (err) {
console.error('Conversion failed:', err.message)
throw err
}
}
convertSVG('./input.svg', './output.svg')
.then(() => console.log('Done!'))
.catch(err => console.error('Fatal error:', err))
```
### Response
#### Success Response (Promise resolves)
- **outlinedSVG** (string) - The SVG content with stroked paths converted to filled paths.
#### Response Example
(See `outlineStroke(input, params)` example for response structure. This example focuses on the usage pattern.)
```
--------------------------------
### Async/Await SVG Outline Conversion (Node.js)
Source: https://context7.com/elrumordelaluz/outline-stroke/llms.txt
Demonstrates converting an SVG file to an outlined SVG using modern async/await syntax for improved error handling and readability. This function reads an input SVG file, outlines it with specified parameters, and writes the result to an output file. It leverages the 'fs.promises' API for asynchronous file operations.
```javascript
const fs = require('fs').promises
const outlineStroke = require('svg-outline-stroke')
async function convertSVG(inputPath, outputPath) {
try {
const svgBuffer = await fs.readFile(inputPath)
const outlined = await outlineStroke(svgBuffer, {
color: '#000000',
background: 'transparent'
})
await fs.writeFile(outputPath, outlined)
console.log(`Successfully converted ${inputPath} to ${outputPath}`)
return outlined
} catch (err) {
console.error('Conversion failed:', err.message)
throw err
}
}
// Usage
convertSVG('./input.svg', './output.svg')
.then(() => console.log('Done!'))
.catch(err => console.error('Fatal error:', err))
```
--------------------------------
### Usage: Outline SVG from String Input
Source: https://github.com/elrumordelaluz/outline-stroke/blob/master/README.md
Demonstrates how to use the svg-outline-stroke library to outline an SVG provided as a string. It takes an SVG string as input and returns a Promise that resolves with the outlined SVG string.
```javascript
const outlineStroke = require('svg-outline-stroke')
const strokedSVG = `
`
outlineStroke(strokedSVG).then(outlined => {
console.log(outlined)
})
```
--------------------------------
### Batch Convert SVG Files using Node.js
Source: https://context7.com/elrumordelaluz/outline-stroke/llms.txt
Processes multiple SVG files in parallel from an input directory to an output directory. It reads SVG files, applies the outline stroke conversion, and writes the processed files. This is useful for build tools or batch conversion workflows. It handles errors for individual files and reports the overall success rate. Dependencies include 'fs', 'path', and 'svg-outline-stroke'.
```javascript
const fs = require('fs').promises
const path = require('path')
const outlineStroke = require('svg-outline-stroke')
async function batchConvert(inputDir, outputDir, params = {}) {
try {
const files = await fs.readdir(inputDir)
const svgFiles = files.filter(f => f.endsWith('.svg'))
console.log(`Processing ${svgFiles.length} SVG files...`)
const results = await Promise.all(
svgFiles.map(async (file) => {
try {
const inputPath = path.join(inputDir, file)
const outputPath = path.join(outputDir, file)
const svgData = await fs.readFile(inputPath)
const outlined = await outlineStroke(svgData, params)
await fs.writeFile(outputPath, outlined)
return { file, success: true }
} catch (err) {
return { file, success: false, error: err.message }
}
})
)
const successful = results.filter(r => r.success).length
console.log(`Completed: ${successful}/${svgFiles.length} files converted`)
return results
} catch (err) {
console.error('Batch conversion error:', err)
throw err
}
}
// Usage
batchConvert('./svg-input', './svg-output', { color: '#333333' })
.then(results => {
const failed = results.filter(r => !r.success)
if (failed.length > 0) {
console.log('Failed files:', failed)
}
})
```
--------------------------------
### outlineStroke(input, params)
Source: https://context7.com/elrumordelaluz/outline-stroke/llms.txt
Converts an SVG with stroked paths into an SVG with filled path outlines. Accepts either a string or Buffer containing SVG data, and optional Potrace parameters for customizing the output. Returns a Promise that resolves to the outlined SVG string.
```APIDOC
## outlineStroke(input, params)
### Description
Converts an SVG with stroked paths into an SVG with filled path outlines. Accepts either a string or Buffer containing SVG data, and optional Potrace parameters for customizing the output.
### Method
Asynchronous Function (returns a Promise)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **input** (string | Buffer) - Required - SVG data as a string or Buffer.
- **params** (object) - Optional - Potrace parameters for customization.
- **color** (string) - Fill color for the outlined paths.
- **background** (string) - Background color of the SVG.
- **threshold** (number) - Blackness threshold for tracing.
- **turnpolicy** (string) - Path optimization strategy (e.g., 'minor', 'major', 'left', 'straight', 'random').
### Request Example
```javascript
const outlineStroke = require('svg-outline-stroke')
const strokedSVG = ``
outlineStroke(strokedSVG)
.then(outlined => {
console.log(outlined)
})
.catch(err => {
console.error('Conversion failed:', err)
})
```
### Response
#### Success Response (Promise resolves)
- **outlinedSVG** (string) - The SVG content with stroked paths converted to filled paths.
#### Response Example
```html
```
```
--------------------------------
### Outline SVG Stroke with Custom Potrace Parameters (Node.js)
Source: https://context7.com/elrumordelaluz/outline-stroke/llms.txt
Converts an SVG with stroked paths into an SVG with filled path outlines, applying custom Potrace parameters for enhanced control over the output. Parameters like 'color', 'background', 'threshold', and 'turnpolicy' can be passed to modify the tracing process and appearance.
```javascript
const outlineStroke = require('svg-outline-stroke')
const strokedSVG = `
`
// With custom fill color and background
outlineStroke(strokedSVG, {
color: '#bada55',
background: '#ffffff',
threshold: 128,
turnpolicy: 'majority'
})
.then(outlined => {
console.log('Outlined SVG with custom colors:', outlined)
})
.catch(err => {
console.error('Error:', err)
})
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.