| Author |
Message |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Thu 08 Sep 2011, 12:47 Post subject:
text2xpm in shell |
|
here is the 1st working stub, I will eventually merge features from my previous xpm generator that would do vertical or horizontal percent bars
usage
text2xpm "your text here" >/tmp/tmp.xpm
It takes ~0.01s to generate a Hello World xpm image
(yes I know it would have been simpler if I used bash arrays, but I want it to be compatible with other shells)
| Code: | #!/bin/ash
#Given string input $1, go char by char & create 7x13 xpm representation
CHARS=" 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~!@#$%^&()_+-=<>,./?;':\"{}[]\|"
ROWA=" # ## # # # # # # ## ## #### #### # # "
ROWB=" ## # #### ###### # ###### ### ###### #### #### ## #### #### #### ###### ###### #### # # ##### ### # # # # # # # #### ##### #### ##### #### ######## # # # # # # # # # ###### # # ## # # # # ## # # # # # ### # # # ## # # # ## # # # #### # # # # # # # # # "
ROWC=" # # ## # # # ## # # # # # # # # # # # # # # # # # # # # # # # # # # ## ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #### # # # # # # # # # # # # # # # # # # # # # # # "
ROWD=" # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ## ## ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ### # # # # # # ## # # # # # # # # # # # # # # # # # # # # "
ROWE=" # # # # # # # ##### # # # # # # # # # # # # # # # # # # # # # # # # ## # ## # # # # # # # # # # # # # # # # # # # # # # #### # ### #### ### # #### # ### # # ### ## ## # # # ## # # ### #### # ### ### # # ### #### ##### # # # # # # # # # # ###### # # # # ##### # # # ### # # # # # ###### # # # # ## ### # # # # # # "
ROWF=" # # # # ### # # # # # ### # ## # ## # # #### # # # #### #### # ###### # # ## # # ## # # # # # # # # # # # # ## # # # # # # # ## # # # # # ## # # # # ## # # ##### # # ## # # # # # # # # # ## # # # ## # # ## ## # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # ## # # # # # # # "
ROWG=" # # # # # # # # ## # # # # ### # ###### # # # # # # # # ### # # # # # # # # # # # # # # ##### # # ##### ## # # # # # # # ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ### # ## # # # ##### ##### # # # # # # # # # # "
ROWH=" # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # ### # # # # # # # # # # # # # # # # ##### # # # # # ###### # # # # # # # ### # # # # # # # # # # # # # ## # # # # # # # # ## # # # # # # # ##### # # ### # # # # # # ###### # # # # # # # # # # "
ROWI=" # # # # # # ###### # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # # # # # # ## # # # # # # # # # # # # # # # # ### # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ## # # ### # # # # # ## # # # # # # # # # ## # # # # # # # "
ROWJ=" # # # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # # # # # # # # # ## # # # # # # # ## # # # # # # # # # ## # # # # ## # # # # # # # # # # # # # # # # # # ## # # ## # # # # # # ## # # # # # # ### # # # # # # # # # # # # # ## # # # # # ## # # # # ### # # # # # # "
ROWK=" ## ##### ###### #### # #### #### # #### ### # # #### #### #### ###### # ### # # # ##### ### # # ###### # # # # #### # #### # # #### # #### ## # # # # # ###### ##### # ### #### ### # #### # # ### # # ##### # # # # ##### # # # # #### # ### ### # # #### ## ### # # # # # # # ###### # #### # # #### # ## ## # # # # # # ### # # # # # # # # # # "
ROWL=" # # # # # # # # # # # # # # # # # # # # # # "
ROWM=" # #### ### # # #### # # ###### # # ## ## #### #### # # "
#echo $CHARS
j=0
while ([ "${j}" -lt "${#1}" ]) do
i=${CHARS%${1:$j:1}*} #cut the string after current char, length = position
i=${#i} #note each ROW{A-M}
RA=${RA}${ROWA:$(( $i*7 )):7}
RB=${RB}${ROWB:$(( $i*7 )):7}
RC=${RC}${ROWC:$(( $i*7 )):7}
RD=${RD}${ROWD:$(( $i*7 )):7}
RE=${RE}${ROWE:$(( $i*7 )):7}
RF=${RF}${ROWF:$(( $i*7 )):7}
RG=${RG}${ROWG:$(( $i*7 )):7}
RH=${RH}${ROWH:$(( $i*7 )):7}
RI=${RI}${ROWI:$(( $i*7 )):7}
RJ=${RJ}${ROWJ:$(( $i*7 )):7}
RK=${RK}${ROWK:$(( $i*7 )):7}
RL=${RL}${ROWL:$(( $i*7 )):7}
RM=${RM}${ROWM:$(( $i*7 )):7}
j=$(($j+1))
done
IMAGE='/* XPM */
static char *tmp_xpm[] = {
"'${#RA}' 13 2 1",
" c #000000",
"# c #FFFFFF",
"'$RA'",
"'$RB'",
"'$RC'",
"'$RD'",
"'$RE'",
"'$RF'",
"'$RG'",
"'$RH'",
"'$RI'",
"'$RJ'",
"'$RK'",
"'$RL'",
"'$RM'"
};'
echo "$IMAGE" |
Edit: ok that is pretty ugly ... uploading the gzipped code
| Description |
|

Download |
| Filename |
text2xpm.gz |
| Filesize |
1.48 KB |
| Downloaded |
106 Time(s) |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Thu 08 Sep 2011, 17:39 Post subject:
|
|
it now accepts bg1= bg2= fg= width= and percent=
TODO vertical bars, maybe rounded corners if I can come up with a clever way to do it?
| Description |
|

Download |
| Filename |
text2xpm.gz |
| Filesize |
1.83 KB |
| Downloaded |
115 Time(s) |
| Description |
|
| Filesize |
18.22 KB |
| Viewed |
654 Time(s) |

|
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 5241 Location: Valåmoen, Norway
|
Posted: Fri 09 Sep 2011, 03:53 Post subject:
|
|
I like this
_________________ Stardust resources
|
|
Back to top
|
|
 |
sunburnt

Joined: 08 Jun 2005 Posts: 4001 Location: Arizona, U.S.A.
|
Posted: Fri 09 Sep 2011, 04:57 Post subject:
|
|
Vertical ones stacked side by side would make a good set of tray meters.
Amounts for: Cpu load, Ram used, Save file used, Dnld. speed, etc.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Fri 09 Sep 2011, 10:43 Post subject:
|
|
The vertically oriented icons are next, I already have the height parameter working (with the text centered vertically... should there be an option to put text on top or bottom?... and left/right/center for that matter?)
I also have a method partially worked out to do graphs(without text), but not sure if there will be a way to integrate it here... its a _little_ more complex
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
sunburnt

Joined: 08 Jun 2005 Posts: 4001 Location: Arizona, U.S.A.
|
Posted: Fri 09 Sep 2011, 16:52 Post subject:
|
|
Text justification is a nicety, if you have a use for it it`s good.
Should be easy to do though...
Centered I`d think would be the most common use / need.
When I made M$ controls and ActiveX I added stuff like this if it was easy.
M$ controls have lots of properties like this, which is overkill mostly.
M$ put lots of effort into nice working controls, and the quality shows.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Fri 09 Sep 2011, 17:37 Post subject:
|
|
Currently if you don't specify a width, it uses the width of your text.
| Code: |
text2xpm "used free" percent=50
|
You would get a justified image with used all the way on the left and free all the way to the right. Think partinfo
(BTW each char is 7 pixels ... width=${#STRING})[/code]
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
sunburnt

Joined: 08 Jun 2005 Posts: 4001 Location: Arizona, U.S.A.
|
Posted: Fri 09 Sep 2011, 17:44 Post subject:
|
|
What about fonts? Maybe as important if not more than justified: left, right, center.
Fonts would potentially change the 7 pixels per character of course.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Fri 09 Sep 2011, 21:22 Post subject:
|
|
There is only 1 font and it is built-in to the script (it looks like a bunch of garbage in the 1st post, but you can see it fine in geany)
You can modify it but it would have to be a fixed width font to work. (otherwise the math would be ridiculously slow)
Like the ones here.
http://www.cfcl.com/vlb/h/fontmono.html
BTW apologies for not adding localization chars.
I just used the text part of mtpaint, cropped and saved as xpm... I don't have the other chars on my keyboard.
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
big_bass

Joined: 13 Aug 2007 Posts: 1736
|
Posted: Fri 09 Sep 2011, 23:18 Post subject:
|
|
Hey technosaurus
this looks interesting
I wonder if this is possible with png format too
using just shell/bash
or even a very small c program
updated using imagemagick you get a nice image
| Code: |
convert -size 200x30 xc:transparent -font /usr/share/fonts/default/TTF/DejaVuSans-BoldOblique.ttf -pointsize 12 -draw "text 5,15 'this is just a test'" test.png
|
Joe
| Description |
|
| Filesize |
1.4 KB |
| Viewed |
610 Time(s) |

|
_________________ slackware 14
Last edited by big_bass on Sat 10 Sep 2011, 10:14; edited 1 time in total
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2419
|
Posted: Sat 10 Sep 2011, 03:48 Post subject:
|
|
..and then add animation. I might use this for a timer.
| Code: |
#!/bin/sh
cd /tmp
for num in $(seq 1 5); do
case "$num" in
1 ) vw one.xpm ; sleep .5 ;;
2 ) vw two.xpm ; sleep .5 ;;
3 ) vw three.xpm ; sleep .5 ;;
4 ) vw four.xpm ; sleep .5 ;;
5 ) vw five.xpm ; sleep .5 ;;
esac
done
kill `pidof viewnior`
|
Crude "working" bar: (vw=viewnior)
| Code: |
for num in $(seq 1 5); do
var="${var}X"
./text2xpm "${var}" bg1=0000FF fg=0000FF >/tmp/"${num}.xpm"
wait
vw /tmp/${num}.xpm
sleep .5
rm /tmp/${num}.xpm
done
kill -9 `pidof viewnior`
|
|
|
Back to top
|
|
 |
big_bass

Joined: 13 Aug 2007 Posts: 1736
|
Posted: Sat 10 Sep 2011, 13:02 Post subject:
|
|
| Quote: | | Vertical ones stacked side by side would make a good set of tray meters. |
I got this tip from imagmagick
you could add this snippet to text2xpm also after some mods
| Code: |
echo -n "Vertical" | sed 's/./&@/g; s/@$//' | tr '@' '\012' |
Note that the "sed" command adds a '@' character after every character,
except at the end of the string.
The "tr" then replaces the '@' characters with newlines.
It also assumes the input text does not end with a newline,
which would cause an extra blank space to be added at the
bottom of the resulting image.
Joe
_________________ slackware 14
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Sun 11 Sep 2011, 01:09 Post subject:
|
|
I have some real world projects to deal with for a while so I am uploading my current development snapshot with some notes.
I currently have added a rounded option, and support for height since the last version, some code improvements and haphazardly put my best guess as to what the code for other options will look like in comments
| Description |
development version with some notes to remind me what to do later, sometime, maybe, eventually
|

Download |
| Filename |
text2xpm.gz |
| Filesize |
2.39 KB |
| Downloaded |
123 Time(s) |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Thu 15 Sep 2011, 10:04 Post subject:
|
|
new todo, support prepended xpm (drive icons for example)
this is an experiment for my jwm-tools project, as it will allow drives icons to display the partition name and optionally percent used/free without needing a tooltip ... freeing up the tooltip to display kb used/free
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
01micko

Joined: 11 Oct 2008 Posts: 7017 Location: qld
|
Posted: Thu 29 Dec 2011, 02:00 Post subject:
|
|
Ok, so I put this to actual use
Note the feature request.
_________________ keep the faith .. 
|
|
Back to top
|
|
 |
|