Skip to content

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 โ€‹

javascript
// 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 โ€‹

javascript
// 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 โ€‹

OptionTypeDefaultDescription
filenamestringAuto-generatedFilename for the exported file (without extension)
preserveTrailingSpacesbooleanfalseKeep trailing spaces on each line
lineEnding'lf' | 'crlf''lf'Line ending format ('lf' for Unix/Linux, 'crlf' for Windows)
emptyCharacterstring' '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 โ€‹

javascript
// 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 โ€‹

javascript
// 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 โ€‹

OptionTypeDefaultDescription
filenamestringAuto-generatedFilename for the exported file (without extension)
includeBackgroundRectanglesbooleantrueInclude cell background rectangles
drawMode'fill' | 'stroke''fill'Character rendering mode
strokeWidthnumber1.0Stroke 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 โ€‹

javascript
// 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 โ€‹

javascript
// 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 โ€‹

OptionTypeDefaultDescription
qualitynumber1.0Quality for JPG/WebP (0.0-1.0, ignored for PNG)
scalenumber1.0Scale factor for output size
backgroundColorstring'black'Background color (CSS color or 'transparent')

Format comparison โ€‹

FormatTransparencyFile SizeQualityBest For
PNGโœ… YesLargeLosslessHigh quality, transparency needed
JPGโŒ NoSmallLossyWeb sharing, smaller files
WebPโœ… YesSmallestLossy/LosslessModern 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:

Ready to share your creations with the world? Start exporting your ASCII masterpieces! ๐ŸŽจ