Exporting โ
Once you've created your ASCII art with textmode.js
, you'll likely want to save or share it. The library provides comprehensive export capabilities to generate your textmode creations in various formats, each optimized for different use cases.
Overview โ
textmode.js
supports exporting your ASCII art in three main formats:
- ๐ TXT - Plain text format for sharing and displaying in terminals
- ๐จ SVG - Scalable vector graphics for web, print and plotting
- ๐ผ๏ธ Images - PNG, JPG, and WebP for general sharing
Text export โ
Text export generates pure ASCII/text content that can be displayed in any text editor, terminal, or shared as plain text.
Basic usage โ
// Get ASCII content as a string
const textContent = textmodifier.toString();
console.log(textContent);
// Save directly to a TXT file
textmodifier.saveStrings({
filename: 'my_ascii_art'
});
Advanced options โ
// Generate with custom options
const textContent = textmodifier.toString({
preserveTrailingSpaces: true,
lineEnding: 'crlf',
emptyCharacter: 'ยท'
});
// Save with options
textmodifier.saveStrings({
filename: 'detailed_ascii_art',
preserveTrailingSpaces: false,
lineEnding: 'lf',
emptyCharacter: ' '
});
Text export options โ
Option | Type | Default | Description |
---|---|---|---|
filename | string | Auto-generated | Filename for the exported file (without extension) |
preserveTrailingSpaces | boolean | false | Keep trailing spaces on each line |
lineEnding | 'lf' | 'crlf' | 'lf' | Line ending format ('lf' for Unix/Linux, 'crlf' for Windows) |
emptyCharacter | string | ' ' | Character to use for empty cells |
Some use cases
- Sharing ASCII art on social media or forums
- Displaying in terminals or console applications
- Creating retro-style documentation
- Generating content for text-based games
SVG export โ
SVG export creates scalable vector graphics that maintain crisp quality at any size and can be easily styled with CSS.
Basic usage โ
// Generate SVG content as a string
const svgContent = textmodifier.toSVG();
// Use the SVG content (e.g., display in DOM)
document.getElementById('svg-container').innerHTML = svgContent;
// Save directly to an SVG file
textmodifier.saveSVG({
filename: 'my_ascii_art'
});
Advanced configuration โ
// Generate with custom styling
const svgContent = textmodifier.toSVG({
includeBackgroundRectangles: true,
drawMode: 'stroke',
strokeWidth: 2.0,
backgroundColor: [255, 255, 255, 255] // White background
});
// Save with professional settings
textmodifier.saveSVG({
filename: 'professional_ascii',
includeBackgroundRectangles: false, // Cleaner output
drawMode: 'fill',
backgroundColor: [0, 0, 0, 0] // Transparent
});
SVG export options โ
Option | Type | Default | Description |
---|---|---|---|
filename | string | Auto-generated | Filename for the exported file (without extension) |
includeBackgroundRectangles | boolean | true | Include cell background rectangles |
drawMode | 'fill' | 'stroke' | 'fill' | Character rendering mode |
strokeWidth | number | 1.0 | Stroke width when using 'stroke' mode |
backgroundColor | [r, g, b, a] | [0, 0, 0, 0] | Background color as RGBA array (0-255) |
Some use cases
- Web integration where scalability is important
- Print media requiring crisp text
- Creating icons or logos from ASCII art
- When you need to style the output with CSS
Image export โ
Image export creates raster images in popular formats, perfect for sharing on social media, embedding in documents, or general use.
Basic usage โ
// Save as PNG (default)
await textmodifier.saveCanvas('my_ascii_art', 'png');
// Save in different formats
await textmodifier.saveCanvas('high_quality', 'webp');
await textmodifier.saveCanvas('compatible', 'jpg');
High-quality export โ
// Export high-resolution image
await textmodifier.saveCanvas('hires_ascii', 'png', {
scale: 3.0, // 3x larger
});
// Export optimized for web
await textmodifier.saveCanvas('web_optimized', 'webp', {
scale: 1.5,
quality: 0.8,
backgroundColor: 'transparent'
});
// Export for print
await textmodifier.saveCanvas('print_ready', 'png', {
scale: 5.0,
});
Image export options โ
Option | Type | Default | Description |
---|---|---|---|
quality | number | 1.0 | Quality for JPG/WebP (0.0-1.0, ignored for PNG) |
scale | number | 1.0 | Scale factor for output size |
backgroundColor | string | 'black' | Background color (CSS color or 'transparent') |
Format comparison โ
Format | Transparency | File Size | Quality | Best For |
---|---|---|---|---|
PNG | โ Yes | Large | Lossless | High quality, transparency needed |
JPG | โ No | Small | Lossy | Web sharing, smaller files |
WebP | โ Yes | Smallest | Lossy/Lossless | Modern web, best compression |
Some use cases
- Social media sharing
- Embedding in documents or presentations
- When vector formats aren't supported
- Creating thumbnails or previews
Next Steps โ
Now that you know how to export your ASCII art, explore these related topics:
- Font Management - Customize typography for different export needs
- API Reference - Detailed documentation of all export options
Ready to share your creations with the world? Start exporting your ASCII masterpieces! ๐จ