Text files displayed as images for thumbnails

Convert Text files to Image format with pango-view.

I just had an idea and it works pretty well. How about showing text file content in the thumbnail area, instead images? The “problem” I had is, that I have tons and tons of Romhacks and Mods. But they lack screenshots (I really should have saved them too). And thus it is a bit difficult to identify what the Mod is all about, other than the filename.

Luckily I saved a text file with information about the particular version of the Romhack alongside the patched Rom. Wouldn’t it be neat to show that text file? Besides, those information are far more valuable than any screenshot in my opinion, especially when it comes to Romhacks, as they often make non visible changes to gameplay too. RetroArch can only show images, so we need to get creative.

I simply converted each text file to an image and put them to a directory with same name as the playlist; in my case “RetroArch” > “thumbnails” > “Nintendo - Super Nintendo Entertainment System - Mods” > “Named_Boxarts” . For that I used a tool called pango-view on the terminal and wrote a simple Bash script. If anyone understands Windows commandline, it would be nice if you share your version of it too.

txt2png.sh:

#!/usr/bin/env bash

# Convert Text files to Image format.
#
# Usage:
#     txt2png desc1.txt desc2.txt
#     txt2png *.txt

for file in "${@}"; do
    pango-view \
        --font mono \
        --no-display \
        --width 320 \
        --height 480 \
        --output "${file%.txt}.png" \
        -- "${file}"
done

And it will generate a .png file for each .txt file. If you have customized options, would be nice if you share it with a screenshot how it looks. At the moment I am currently unsure what settings to use and will probably make adjustments over time.

BTW, this could be used alongside screenshots, for any other game too (not only for Mods and Romhacks). On PC with the Right bottom Shift-key Boxarts can be toggled in the GUI of RetroArch.

3 Likes

Many years ago I wanted to do this (to show some system info, if I recall correctly), but didn’t know of a tool like pango-view that could generate the images.

Thanks for this!

2 Likes

Tip for RetroArch: On PC, the spacebar on your keyboard will show the image in bigger format. Especially useful for handhelds like the Steam Deck (start button here, instead spacebar).

I experimented a bit more, because the text was almost unreadable on my Steam Deck. This is on the Steam Deck even more useful, because looking up text files or the internet about a specific Romhack in question is a bit annoying. Having this description ready to be shown in RetroArch as an image is very useful to me.

Also my personal collection of copy/paste descriptions for each Romhack is a bit dirty. That means lot of empty lines and some other nonsense, as I did not clean it up when generating the file. So with the new version of my script I cleanup some of this nonsense and also be able to change the font size finally (man its so simple actually, but took me long time to figure it out).

I uploaded the script, so anyone interested into it can study to understand how pango-view works on the commandline:

#!/usr/bin/env bash

# (This version is specific for my special use case of personal documents.)
# Version 1.1
# 2025-04-07
#
# Convert Text files to Image format.
#
# Usage:
#     txt2png desc1.txt desc2.txt
#     txt2png *.txt

# Use pango-list to list available fonts.

cleanup() {
    local path
    path="${1}"

    # Remove last whitespace character of each line.
    sed -i 's/ $//g' -- "${path}"

    # Delete lines that are image filenames only, as these are just artifacts
    # from manual copy/paste manouver.
    sed -i -E '/^[a-zA-Z]+\.(png|gif|jpg)$/d' -- "${path}"

    # I added this simple string at the beginning of some files. Its not
    # needed for the created image.
    sed -i '/^sonicretro$/d' -- "${path}"

    # From Metroid, unneeded copy paste parts.
    sed -E -i '/^Forum Thread:.+$/d' -- "${path}"

    cat -- "${path}" | tr '\n' '\r' >>"${path}.tmp2"
    mv -f -- "${path}.tmp2" "${path}"

    sed -i -E \
        -e 's/(\(Note:)\r+/\1  /' \
        -e 's/(From.+:)\r+/\1  /' \
        -e 's/(Hack Name:)\r+/\1  /' \
        -e 's/(Hack of:)\r+/\1  /' \
        -e 's/(Platform:)\r+/\1  /' \
        -e 's/(Released by:)\r+/\1  /' \
        -e 's/(Language:)\r+/\1  /' \
        -e 's/(Status:)\r+/\1  /' \
        -e 's/(Patch Version:)\r+/\1  /' \
        -e 's/(Last updated:)\r+/\1  /' \
        -e 's/(Type of Hack:)\r+/\1  /' \
        -e 's/(Downloads:)\r+/\1  /' \
        -e 's/(Awards:)\r+/\1  /' \
        -- "${path}"

    cat -- "${path}" | tr '\r' '\n' >>"${path}.tmp2"
    mv -f -- "${path}.tmp2" "${path}"

    # Compress multiple blank lines into one line.
    sed -i '/^$/N;/^\n$/D' -- "${path}"

    # Remove the beginning and end of file empty lines only.
    sed -i -e '/./,$!d' -e :a -e '/^\n*$/{$d;N;ba' -e '}' -- "${path}"
}

font_name='Liberation Mono'
font_size='16'

convert() {
    local text_path
    local image_path
    text_path="${1}"
    image_path="${2}"

    pango-view \
        --font "${font_name}, ${font_size}" \
        --antialias subpixel \
        --hinting auto \
        --hint-metrics on \
        --line-spacing 0.95 \
        --width 480 \
        --height 640 \
        --no-display \
        --output "${image_path}" \
        -- "${text_path}"
}

for file in "${@}"; do
    text_tmp="${file}.tmp"
    png_out="${text_tmp%.txt.tmp}.png"

    echo "${file}"
    cp -- "${file}" "${text_tmp}"
    cleanup "${text_tmp}"
    convert "${text_tmp}" "${png_out}"
    rm -- "${text_tmp}"
done