Rockin’ it 8-bit (thanks to Maryke)

Rockin’ it 8-bit (thanks to @maryke87)

Instagram filter used: Normal

View in Instagram ⇒

Made with:

#!/bin/bash
# selfi.sh - strongly influenced by Interstellar Selfie Station
#                          http://interstellarselfiestation.com
# scruss - 2014-06-26

anytopnm "$1" |\
  pnmscale -xsize 160 |\
  pnmhisteq |\
  ppmdither -red 4 -green 4 -blue 4 |\
  ppmtopgm |\
  pnmremap -mapfile < (echo P3 4 1 255 108 108 78 142 139 97 195 196 165 227 230 201) |\
  pnmscale -nomix 2 |\
  pnmtopng > "${1%.*}-selfi_sh.png"

chroma key screen grabs

Oddly-shaped windows are a pain to screen grab. Netpbm to the rescue!

  1. Make a blue (or green, or whatever isn’t used in your window) image larger than the window, like this:
    ppmmake blue 800 600 | pnmtopng > ~/Desktop/b.png
  2. Display the image, and arrange your program in front of it.
  3. Take a screenshot.
  4. Crop the image, and set the background transparent.
    pngtopnm Screen\ shot\ 2011-03-27\ at\ 10.12.52\ .png |\
     pnmcrop |\
     pnmtopng -transparent blue > ICP-2007.png

Ta-dah!

(and yeah, this is a Windows program running under Wine on OS X …)

creating a TrueType font from your handwriting with your scanner, your printer, and FontForge

Hey, this post is super old!
That means that installation and run instructions may not work as well, or even at all. Most of the *Ports Apple software repositories have given way to Homebrew: you may have some success on Mac (untested by me) if you brew install netpbm fontforge potrace. There’s also some font cleanup I’d recommend, like resolving overlaps, adding extrema, and rounding points to integer. One day I may update this post, but for now, I’m leaving it as is.

This looks more than a bit like my handwriting

because it is my handwriting! Sure, the spacing of the punctuation needs major work, and I could have fiddled with the baseline alignment, but it’s legible, which is more than can usually be said of my own chicken-scratch.

This process is a little fiddly, but all the parts are free, and it uses free software. This all runs from the command line. I wrote and tested this on a Mac (with some packages installed from DarwinPorts), but it should run on Linux. It might need Cygwin under Windows; I don’t know.

Software you will need:

  • a working Perl interpreter
  • NetPBM, the free graphics converter toolkit
  • FontForge, the amazing free font editor. (Yes, I said amazing. I didn’t say easy to use …)
  • autotrace or potrace so that FontForge can convert the scanned bitmaps to vectors
  • some kind of bitmap editor.

You will need to download

  • fonttrace.pl – splits up a (very particular) bitmap grid into character cells
  • chargrid.pdf – the font grid template for printing

Procedure:

  1. Print at least the first page of chargrid.pdf. The second page is guidelines that you can place under the page. This doesn’t work very well if you use thick paper.
  2. Draw your characters in the boxes. Keep well within the lines; there’s nothing clever about how fonttrace.pl splits the page up.
  3. Scan the page, making sure the page is as straight as possible and the scanner glass is spotless. You want to scan in greyscale or black and white.
  4. Crop/rotate/skew the page so the very corners of the character grid table are at the edges of the image, like this: I find it helpful at this stage to clean off any specks/macules. I also scale and threshold the image so I get a very dark image at 300-600dpi.
  5. Save the image as a Portable Bitmap (PBM). It has to be 1-bit black and white. You might want to put a new font in a new folder, as the next stage creates lots of files, and might overwrite your old work.
  6. Run fonttrace.pl like this:
    fonttrace.pl infile.pbm | sh
    If you miss out the call to the shell, it will just print out the commands it would have run to create the character tiles.
  7. This should result in a bunch of files called uniNNNN.png in the current folder, like these:
    W
    uni0057.png
    i
    uni0069.png
    s
    uni0073.png
    p
    uni0070.png

    y
    uni0079.png
  8. Fire up FontForge. You’ll want to create a New font. Now File→Import…, and use Image Template as the format. Point it at the first of the image tiles (uni0020.png), and Import.
  9. Select Edit→Select→All, then Element→Autotrace. You’ll see your characters appear in the main window.
  10. And that’s – almost – it. You’ll need to fiddle with (auto)spacing, set up some kerning tables, set the font name (in Element→Font Info … – and you’ll probably want to set the em scale to 1024, as TrueType fonts like powers of two), then File→Generate Fonts. Fontforge will throw you a bunch of warnings and suggestions, and I’d recommend reading the help to find out what they mean.

There are a couple of limitations to the process:

  • Most of the above process could be written into a FontForge script to make things easier
  • Only ASCII characters are supported, to keep the number of scanned pages simple. Sorry. I’d really like to support more. You’re free to build on this.

Lastly, a couple of extra files:

  • CrapHand2.pbm – a sample array drawn by me, gzipped for your inconvenience (and no, I don’t know why WordPress is changing the file extension to ‘pbm_’ either).
  • chargrid.ods – the OpenOffice spreadsheet used to make chargrid.pdf

Have fun! Write nicely!

pgmrnoise – a more random (or less repeatable) pgmnoise

Update: If you have a recent NetPBM, this is fixed.
I’d previously alluded that netpbm’s pgmnoise wasn’t as random as it could be if you called it several times in quick succession. Nerdy discussion after the break, but here’s a (perhaps slightly linux-centric) alternative:

#!/bin/sh
# pgmrnoise - a more random pgmnoise; limited to 8-bit images
# created by scruss on Sun Oct 12 19:36:37 EDT 2008

echo P5
echo $1 $2
echo 255
dd if=/dev/urandom bs=$1 count=$2 2> /dev/null

I just pasted the shell text in there; you’ll need to save it as a file. It works the same way as pgmnoise:

 pgmrnoise width height > noise.pgm

It is limited as written to 8 bit-per-pixel output, but is a fairly trivial edit to make it 16 or more bits.

Continue reading “pgmrnoise – a more random (or less repeatable) pgmnoise”

demented tiles for demented people

I’d totally put these up on my walls, but I may end up climbing them:

I made them by taking 32×32 pixel tiles of random grey noise, Atkinson dithering them (using pamditherbw) then vectorizing them using potrace. If you click on the tiles, you can download/view the PDF source of each.

(pgmnoise, the source of the grey noise, relies heavily on the system time as its seed. Before I introduced a delay between image generation, several images appeared almost identical.)

an appropriate use of company time

$ pbmtext Hello | pnmcrop | pnmtopnm -plain | tail +3 | tr '01' ' #'
###  ###       ## ##
 #    #         #  #
 #    #         #  #
 #    #    ##   #  #   ##
 ######   #  #  #  #  #  #
 #    #   ####  #  #  #  #
 #    #   #     #  #  #  #
 #    #   ##  # #  #  #  #
###  ###   ### ######  ##

Lady Goosepelt Rides Again!

Lady Goosepelt, from What a Life!

In case anyone wants them, the 600 dpi page images of What a Life! are stored in this PDF: what_a_life.pdf (16MB). If you merely wish to browse, all the images from the book are here.

I got a bit carried away with doing this. Instead of just smacking together all the 360 dpi TIFFs I scanned seven years ago, I had to scan a new set at a higher resolution, then crop them, then fix the page numbers, add chapter marks, and make the table of contents a set of live links.

I’ve got out of the way of thinking in PostScript, so I spent some time looking for tools that would do things graphically. Bah! These things’d cost a fortune, so armed only with netpbm, libtiff, ghostscript, the pdfmark reference, Aquamacs, awk to add content based on the DSC, and gimp to work out the link zones on the contents page, I made it all go. Even I’m impressed.

One thing that didn’t impress me, though:

aquamacs file size warning

I used to edit multi-gigabyte files with emacs on Suns. They never used to complain like this. They just loaded (admittedly fairly slowly) and let me do my thing. Real emacs don’t give warning messages.

appalling office samizdat generator

Remember when office walls were festooned with grubby, wonkily photocopied slogans, bad attempts at Snoopy cartoons, and all manner of xerox-worn paperwork? Something like this:
donthavetobemad.jpg

With everything being digital, and e-mailed the world over without degradation, I became nostalgic for the old analogue days. So I decided to emulate the squint, black-edged, mottled, heavily-thresholded imagery with the NetPBM toolkit and a shell script. You can download it here: pnmcopier – emulate a badly-photocopied document to stdout. It should work on most Unix machines. It does require that your shells sets $RANDOM, which might make it a bit bash-specific.

It works best with a fairly high resolution image. Be advised it’s a processor hog; it has to rotate, smooth and merge very large images. To compound the effect, pipe the output into pnmcopier, perhaps several times. I don’t quite have the parameters right, but it gives the desired level of grubbiness. Sorry I couldn’t reproduce coffee stains, staple marks, old tape ghosts or random doodles.

Do what you will with it, but harm none.