Text Images

From Publication Station
Revision as of 09:56, 17 October 2019 by Andre (talk | contribs) (→‎Pi cheat sheet)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Text Images

Pad: https://stuff2233.club/padlife/p/text-images

Text Images/documentation

Announcement text

What are digital (bit-map) images? In their simpler form nothing more but sequence of pixels, each with its color value, organized into lines and rows. Such form of representing image information is uncannily similar to how text is represented digitally: a line-by-line sequence of characters, each with its corresponding value (code point). Can this similarity be used to transform pixel-based images into similar looking images made solely by text?


Material

  • raspberry Pi
  • camera (webcam)
  • LCD screen (HDMI input)
  • speakers (from action)
  • typewriter

Raspberry Pi software

  • Ascii art: figlet cowsay jp2a hasciicam
  • imaging: imagemagick fbi
  • audio: espeak
  • editor: ne (nice editor)


Sessions

Day 1 - Tue 23Jan

Excelfie

http://luciadossin.net/excelfie.html

What is happening in this work?

3excelfie-derivation1.png
Excelfie at Zinecamp 2017

Typewriter Art

TypewriterArt.jpg

Download PDF

Typewritermanual.jpg Newspaper.jpeg


ASCII Art

 _______________
< ASCII??ART??? >
 ---------------
        \   ^__^
         \  (xx)\_______
            (__)\       )\/\
             U  ||----w |
                ||     ||

ASCII art is text art created with ASCII, a protocol established by the American National Standards Institute (ANSI), which is America's representative to the International Organization for Standardization (IOS). ASCII art uses ASCII text characters to produce images. The emoticon, an element of text messaging and email, is an example of ASCII art at its most popular and functional. [1]

Ascii Art as an idea coalesced into existence bceause people

wanted more. They wanted more than just your standard Hercules display Atari or your Monochrome Commodore 64. To meet this demand, one singular artist, whose name is lost to the annals of history decided to take the plunge. Instead of text, he (or she) had the ingenuity to use the characters /, \, |, -, _ and whatever else came to mind to create words. An amazing idea. [2]



ASCII encoding

USASCII code chart.png

{{#widget:Youtube|id=MijmeoH9LT4}}



Plain-text

Plain-text files Binary files
Each byte (8bits sequence) represents one ASCII character there is no one-to-one mapping between bytes and characters
Do not include any formatting information: only text Can have all sorts of formatting, like a Word doc, PDF, or image
are read/written with plain-text editors; or less cat commands data can be interpreted by supporting programs, but will show up as garbled text in a text need specific applications, depending on the file, i.e. Word for .doc. PDF-viewer for PDF
Are less likely to become corrupted, a small error shows up as a typo A small error may make it unreadable
common file formats: ?? common file formats: ??

Exercise: a text-based image

Create a piece of typewriter art or ASCII art.

Day 2 - Wed 24Jan

UNIX

  • it was time-sharing system, allowing for mutiples users to login to the machine ssh username@machineIP
  • included the shell: a program which performs command line interpretation
    • whoaim
    • pwd print working directory - where am I?
    • date
    • users print the user names of users currently logged in to the current host
    • history commands' history
  • tree-structured file system
    • tree ~/ list contents of home (~ == /home/username ) in a tree-like format
    • ls ~ list files and directories in your user home ( ~ == /home/username )
    • ls . list files and directories in current directory ( . == current dir )
    • ls ../ list files and directories in parent directory ( . == current dir )
    • ls foo/ list files and directories in child foo/ directory
    • ls / list files and directories in root ( / == root )
  • every thing is a file
    • ls -R / > /dev/dsp file-system as sound

Others emerged from the development and use of the system and crystallized into the Unix Philosophy:

  • Write programs that do one thing and one thing well
    • ls lists files in a directory
    • cat outputs content of file
    • wc counts number of words in file
  • Write programs that work together
    • echo "hello UNIX world" | sed 's/o/0/g' | sed 's/e/3/g' | sed 's/l/1/g' | figlet
  • Write programs that handle text streams, because that is a universal interface
    • man -a intro | espeak Linux introduction to user commands.


Essential commands

For a PDF with Unix/Linux Command Reference - download the following link

System Info

date – Show the current date and time
cal – Show this month's calendar
uptime – Show current uptime
w – Display who is online
whoami – Who you are logged in as
finger user – Display information about user
uname -a – Show kernel information
cat /proc/cpuinfo – CPU information
cat /proc/meminfo – Memory information
df -h – Show disk usage
du – Show directory space usage
free – Show memory and swap usage

Keyboard Shortcuts

Enter – Run the command
Up Arrow – Show the previous command
Ctrl + R – Allows you to type a part of the command you're looking for and finds it

Ctrl + Z – Stops the current command, resume with fg in the foreground or bg in the background
Ctrl + C – Halts the current command, cancel the current operation and/or start with a fresh new line
Ctrl + L – Clear the screen

command | less – Allows the scrolling of the bash command window using Shift + Up Arrow and Shift + Down Arrow
!! – Repeats the last command
command !$ – Repeats the last argument of the previous command
Esc + . (a period) – Insert the last argument of the previous command on the fly, which enables you to edit it before executing the command

Ctrl + A – Return to the start of the command you're typing
Ctrl + E – Go to the end of the command you're typing
Ctrl + U – Cut everything before the cursor to a special clipboard, erases the whole line
Ctrl + K – Cut everything after the cursor to a special clipboard
Ctrl + Y – Paste from the special clipboard that Ctrl + U and Ctrl + K save their data to
Ctrl + T – Swap the two characters before the cursor (you can actually use this to transport a character from the left to the right, try it!)
Ctrl + W – Delete the word / argument left of the cursor in the current line

Ctrl + D – Log out of current session, similar to exit

Learn more about Commands/programs

apropos subject – List manual pages for subject
man -k keyword – Display man pages containing keyword
man command – Show the manual for command
man -t man | ps2pdf - > man.pdf – Make a pdf of a manual page
which command – Show full path name of command
time command – See how long a command takes

whereis app – Show possible locations of app
which app – Show which app will be run by default; it shows the full path

File Commands

ls – Directory listing
ls -l – List files in current directory using long format
ls -laC – List all files in current directory in long format and display in columns
ls -F – List files in current directory and indicate the file type
ls -al – Formatted listing with hidden files

cd dir – Change directory to dir
cd – Change to home
mkdir dir – Create a directory dir
pwd – Show current directory

rm name – Remove a file or directory called name
rm -r dir – Delete directory dir
rm -f file – Force remove file
rm -rf dir – Force remove an entire directory dir and all it’s included files and subdirectories (use with extreme caution)

cp file1 file2 – Copy file1 to file2
cp -r dir1 dir2 – Copy dir1 to dir2; create dir2 if it doesn't exist
cp file /home/dirname – Copy the filename called file to the /home/dirname directory

mv file /home/dirname – Move the file called filename to the /home/dirname directory
mv file1 file2 – Rename or move file1 to file2; if file2 is an existing directory, moves file1 into directory file2

more file – Display the file called file one page at a time, proceed to next page using the spacebar
head file – Output the first 10 lines of file
head -20 file – Display the first 20 lines of the file called file
tail file – Output the last 10 lines of file
tail -20 file – Display the last 20 lines of the file called file
tail -f file – Output the contents of file as it grows, starting with the last 10 lines


SSH

ssh user@host – Connect to host as user
ssh -p port user@host – Connect to host on port port as user
ssh-copy-id user@host – Add your key to host for user to enable a keyed or passwordless login


meta characters

Meta Characters are characters that have special meaning within the terminal

  • ~ the tilde stands for the user's home. cd ~/ change directory to home
  • . dot stands for this directory. ls . list this directory
  • .. dot dot stands for the parent directory to this directory. cp myfile.jpg .. copy myfile.jpg to the parent directory
  • * asterisk is a wildcards which represents zero or more characters ls P*.jpg will list all the files, in the current directory, that begin with P and end with .jpg
  • \ backslash it is a literal character. It escape the meta value of the meta-characters and display them only as literal characters. echo Foo \* will output Foo * If \ wasn't there it would output all the files in that directory.


pipes, write to & append

A pipes (" | ") sends the output of one program to the input of another program.

echo "my sentence"| wc the echoed sentence "my sentence" is pipped into the program wc which counts the number of lines, words, and characters


> Writes the output of a command to a file, rather than to print on terminal.

df > df_output.txt redirect the content of man dfM to a file called df_output.txt

If the said file doesn't exit it will create it, if it already exists it will overwrite its contents/


>> appends the output of a command to a file, without overwriting the original file. echo 'also add this' >> df_output.txt will add 'also add this' to the contents of df_output.txt


Proto social network tools

wall - write a message to all users echo "how is the weather in your terminal?|wall"


write enables you to chat with another user. You can find who is logged in and to which terminal with the who command.

Once you got the name and tty of whom you want to chat with you can start writing to him/her write username tty


ASCII Art tools

  • figlet - display large characters made up of ordinary screen characters echo "say something big"|figlet
  • coway - cowsay/cowthink - configurable speaking/thinking cow echo "look,I am a cow"|figlet
  • jp2a - converts JPEG images to ASCII

jp2a image.jpg


Day 3 - Wed 25Jan: Bitmap

Software:

  • imagemagick: a command-line program for image manipulation. We will be using it mainly through the command convert which convert 1 image onto another.
  • fbi (frame-buffer image): displays the specified file(s) on the linux console using the framebuffer device

ftp

Use Filezilla to transfer files from your computer to the Pi and vice-versa

bitmap images

You probably have heard before that bitmap images are grids of pixels, where

  • resolution: the number of horizontal and vertical pixels. E.g. 1920x1080 is 1920 pixels wide and 1080 high
  • color depth: the number of bits used to indicate the color of a single pixel

for a good introduction to bit maps see: See Bourke, Paul. n.d. ‘A Beginners Guide to Bitmaps’. Accessed 2 January 2018. http://paulbourke.net/dataformats/bitmaps/.


Resolutions:

Color depth - (use microscope)

  • 1-bit color (21 = 2 colors): monochrome, often black and white, compact Macintoshes, Atari ST.
  • 2-bit color (22 = 4 colors): CGA, gray-scale early NeXTstation, color Macintoshes, Atari ST.
  • 3-bit color (23 = 8 colors): many early home computers with TV displays, including the ZX Spectrum and BBC Micro
  • 4-bit color (24 = 16 colors): as used by EGA and by the least common denominator VGA standard at higher resolution, color Macintoshes, Atari ST, Commodore 64, Amstrad CPC.
  • 5-bit color (25 = 32 colors): Original Amiga chipset
  • 6-bit color (26 = 64 colors): Original Amiga chipset
  • 8-bit color (28 = 256 colors): most early color Unix workstations, VGA at low resolution, Super VGA, color Macintoshes, Atari TT, Amiga AGA chipset, Falcon030, Acorn Archimedes.
  • 12-bit color (212 = 4096 colors): some Silicon Graphics systems, Color NeXTstation systems, and Amiga systems in HAM mode.
  • 8-bit color: A very limited but true direct color system, there are 3 bits (8 possible levels) for each of the R and G components, and the two remaining bits in the byte pixel to the B component (four levels), enabling 256 (8 × 8 × 4) different colors.
  • Grey scale (8-bit)
  • True color (24-bit): Usually, true color is defined to mean 256 shades of red, green, and blue, for a total of 224, or alternately 2563, or 16,777,216 color variations. The human eye can discriminate up to ten million colors

[3]


{{#widget:Youtube|id=06OHflWNCOE}}



converting resolution

with Imagemagick

to 100px wide

convert myimage.jpg -resize 100x output.jpg 

to 100px hight

convert myimage.jpg -resize x100 output.jpg 

to 100x100px (image will loose its proportion; hence the "!" so imagemagick is sure that you wanna do that:)

convert myimage.jpg -resize 100x100! output.jpg 

converting color (bit depth)

convert an image into monochrome (1 bit depth) image: 2color values (b/w)

convert myimage.jpg -colorspace gray -depth 1 out.png

(2 bit depth) image: 4 color values

convert myimage.jpg -colorspace gray -depth 2 out.png

(3 bit depth) image: 8 color values

convert myimage.jpg -colorspace gray -depth 3 out.png

(4 bit depth) image: 16 color values

convert myimage.jpg -colorspace gray -depth 4 out.png

(8 bit depth) image: 256 color values

convert myimage.jpg -colorspace gray -depth 4 out.png


How can we be certain about this? How do can we see the grid that forms a bitmap image?

  • magnify any digital screen
  • a Plain-text bitmap: where you can read each pixel: X PixMap (XPM)

X PixMap (XPM) is a plain-text bitmap image format, where each color is assigned a character, which is mapped onto the text space.

convert myimage.jpg out.xpm


/* XPM */
static char *output[] = {
/* columns rows colors chars-per-pixel */
"50 73 2 1 ",
"  c black",
". c white",
/* pixels */
"                                                  ",
"                                                  ",
"                                                  ",
"                                                  ",
"               ................                   ",
"           ......   . .. . . .......              ",
"          .. .           .         ...            ",
"         . .   .. .            .     ..           ",
"        .. . .    .    .  .     .     .           ",
"        .   .      .    .   .    . .  ..          ",
"        .  .        .  .       .    . .           ",
"        ...          ..      .       ..           ",
"       ...              .. .         ...          ",
"        ..                            .           ",
"        .                             ..          ",
"        ..                            .           ",
"        .                             ..          ",
"       ...      .                     .           ",
"        .     .                       .           ",
"       ..                             .           ",
"       ..  .    .                   . .           ",
"        .    .                        .           ",
"       ..  .  .....                   .           ",
"        .    ..   ..                  .           ",
"        .   .       ..            .   .           ",
"       .  ..         .               ..           ",
"       .. .    .     .            .....           ",
"          .   ...     .          .    .           ",
"       .  .   ....   ..          .    ..          ",
"       . ..   ....              .      .          ",
"        . .          .          .    ....         ",
"       .  .          .          ..   ...          ",
"          .          .           .    ..          ",
"       ..  .        .            .     .          ",
"       .   .       ..            .    .           ",
"       .    ..   ..               ..  ..          ",
"       ..     ...                  ... .          ",
"      ..                               ..         ",
"      .                  .  .       .   .         ",
"     .  .  ..                           .         ",
"     .  . ....                     .    .         ",
"     .    ..  ...   .              ..  ..         ",
"     .. .  ..  .....   . ..   .   ...  .          ",
"      .    ... ..  ....          ....  .          ",
"       .    .....   ......     ...... .           ",
"       ..    . ..... .  ......... ... .           ",
"        ..   .........   .. .  ...... .           ",
"         .    ..   ....................           ",
"         .     ..   . ............... .           ",
"          .     .. ..   ............. .           ",
"           .      ..    .   .  .....  .           ",
"           ...  .  ...  .  .. ......  .           ",
"            ... .    .............    .           ",
"              ..   .       ..          .          ",
"               ...   ..                           ",
"                 ...     .    .       ..          ",
"                   ..            .    .           ",
"                     ..               .           ",
"                       ....          ..           ",
"                          .....  ....             ",
"                              .....               ",
"                                                  ",
"                                     .            ",
"                   ..   .            ...          ",
"        ...  .. ..  ... .. .. ...... ...          ",
"        ............................  ..          ",
"        ...... ................. ...  .           ",
"        ......  ... ... ..... .... .. .           ",
"        ..                                        ",
"        .                                         ",
"                                                  ",
"                                                  ",
"                                                  "
};



{{#widget:Youtube|id=UBX2QQHlQ_I}}

Day 3- Thursday

ASCII animation

ne: nice editor

F1 - menu

Day 4 Friday

  • FTP
  • Dot matrix
  • sound

Sound

espeak

echo "Can you hear me?" | espeak

mpv

mpv audiofile.mp3


Dot Matrix printers: escpos

Using python escpos

with Kube


With the Fujitsu DL6600:

In [11]: f=Serial(devfile=u'/dev/ttyUSB0', baudrate=9600, bytesize=8, timeout=1, parity='N', stopbits=1, xonxoff=False, dsrdtr=True)
Serial printer enabled

In [12]: f.text('test')

In [13]: f.close()

Day 4 - Friday 26Jan: Bitmap outside the screen

The challenge for today is how to do we get out bitmap/ascii-art/plain-text image out from the screen and materialize it into something.

  • a silk screen print ?
  • a sound composition
  • ?





Capturing image

  • fswebcam/xawtv: capture camera

fswebcam: no visual feedback

fswebcam --device  /dev/video0 --no-banner --save test.jpg

mpv: screen shot by typing "s"

mpv /dev/video0



Capturing camera input

Assembling it all

Pi cheat sheet

display image in Terminal 1 with

fbi capture.jpg -T 1

picam; but Picam seems difficult to work with other software - should try webcam

raspistill -o test.jpg 

There is a python module for it: https://pzwiki.wdka.nl/mediadesign/PiCam

references

  1. ‘ASCII ART’. n.d. Accessed 2 January 2018. http://artscene.textfiles.com/information/ascii-newmedia.txt
  2. Necromancer. 1998. ‘History of the PC Ascii Scene’. March 1998. http://artscene.textfiles.com/history/essays/pcascii.txt
  3. https://en.wikipedia.org/wiki/Color_depth