• bash help

    From bad sector@forgetski@_INVALID.net to alt.os.linux on Sat Nov 8 11:09:51 2025
    From Newsgroup: alt.os.linux


    Here's a snipet from my _flintstones_ bash script
    aiming to generate an image of the number that is
    the variable 'size'.


    output_file="number_image.png"
    # 'imagemagic convert' the number to an image
    # the old 'convert' is now 'magic'
    magick -pointsize 90 \
    -fill "#cccccc" -background "#002200" label:"$size" "$output_file"

    I use 'feh' to splash random (quiz) numbers right onto the kde desktop
    but the current code does not format and I end up with unplesant
    transparency holes.

    I'd like to upgrade the script so as to generate image 'output_file' as
    the white image of a 4 digit number with up to 3 leading zeros on a
    black background, or up to 3 leading black spaces insted of zeros.

    TIA


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Brock McNuggets@brock.mcnuggets@gmail.com to alt.os.linux on Sat Nov 8 17:40:06 2025
    From Newsgroup: alt.os.linux

    On Nov 8, 2025 at 9:09:51 AM MST, "bad sector" wrote <8R-cnUwRkr7E9pL0nZ2dnZfqn_qdnZ2d@giganews.com>:


    Here's a snipet from my _flintstones_ bash script
    aiming to generate an image of the number that is
    the variable 'size'.


    output_file="number_image.png"
    # 'imagemagic convert' the number to an image
    # the old 'convert' is now 'magic'
    magick -pointsize 90 \
    -fill "#cccccc" -background "#002200" label:"$size" "$output_file"

    I use 'feh' to splash random (quiz) numbers right onto the kde desktop
    but the current code does not format and I end up with unplesant
    transparency holes.

    I'd like to upgrade the script so as to generate image 'output_file' as
    the white image of a 4 digit number with up to 3 leading zeros on a
    black background, or up to 3 leading black spaces insted of zeros.

    TIA

    #!/bin/bash

    size="$1"
    output_file="number_image.png"

    # Pad with zeros (or spaces)
    formatted=$(printf "%04d" "$size")

    # Generate the image
    convert -size 300x120 \
    -background black \
    -fill white \
    -font DejaVu-Sans-Bold \
    -gravity center \
    -pointsize 90 \
    label:"$formatted" \
    "$output_file"

    -----

    Saves it to your home folder. Of course you can change the path as you wish. Tested on Ubuntu and it worked.

    I did use ChatGPT to help me make this... if that matters.
    --
    It's impossible for someone who is at war with themselves to be at peace with you.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From bad sector@forgetski@_INVALID.net to alt.os.linux on Sat Nov 8 22:29:01 2025
    From Newsgroup: alt.os.linux

    On 11/8/25 12:40 PM, Brock McNuggets wrote:
    On Nov 8, 2025 at 9:09:51 AM MST, "bad sector" wrote <8R-cnUwRkr7E9pL0nZ2dnZfqn_qdnZ2d@giganews.com>:


    Here's a snipet from my _flintstones_ bash script
    aiming to generate an image of the number that is
    the variable 'size'.


    output_file="number_image.png"
    # 'imagemagic convert' the number to an image
    # the old 'convert' is now 'magic'
    magick -pointsize 90 \
    -fill "#cccccc" -background "#002200" label:"$size" "$output_file"

    I use 'feh' to splash random (quiz) numbers right onto the kde desktop
    but the current code does not format and I end up with unplesant
    transparency holes.

    I'd like to upgrade the script so as to generate image 'output_file' as
    the white image of a 4 digit number with up to 3 leading zeros on a
    black background, or up to 3 leading black spaces insted of zeros.

    TIA

    #!/bin/bash

    size="$1"
    output_file="number_image.png"

    # Pad with zeros (or spaces)
    formatted=$(printf "%04d" "$size")

    # Generate the image
    convert -size 300x120 \
    -background black \
    -fill white \
    -font DejaVu-Sans-Bold \
    -gravity center \
    -pointsize 90 \
    label:"$formatted" \
    "$output_file"

    -----

    Saves it to your home folder. Of course you can change the path as you wish. Tested on Ubuntu and it worked.

    I did use ChatGPT to help me make this... if that matters.

    Chatgpt has been dumping on me lately, and if everyone uses it then
    usenet will give up the ghost, it's already half way there.

    But it's a good idea in this case. This time it came up with this (and
    it works):

    padded=$(printf "%6s " "$size" | sed 's/ /\\ /g')
    magick -pointsize 90 \
    -gravity center \
    -font DejaVu-Sans-Bold \
    -fill "#cccccc" \
    -background "#002200" \
    label:"$padded" \
    "$output_file"


    --- Synchronet 3.21a-Linux NewsLink 1.2