martes, 2 de junio de 2009

Jeroglíficos


Mala fama tiene la línea de comando: inescrutable, críptica, y sólo apta para los iniciados en tan oscuro saber.

¿Qúe mejor para perpetuar esa fama que escribir jeroglíficos con comandos? ;-)

Ingredientes:
  • xgawk
  • un tipo de letra adecuado, Greywolf Glyphs
  • un sencillo script, que denominaremos jeroglífico.awk.
El sencillo script es éste, donde en lugar de comentarios he preferido poner "print" para ir mostrando los pasos:

@load gd

BEGIN {
MARGEN = 8
TAM_LETRA = 48
TIPO_LETRA = "GWGLYPTT.ttf"
if (!("GDFONTPATH" in ENVIRON)) {
print "\n¡¡Recuerda definir GDFONTPATH!!\nHaz algo parecido a ...\n"
print "GDFONTPATH=/cygdrive/c/WINDOWS/Fonts/:/usr/X11R6/lib/X11/fonts/TTF/; export GDFONTPATH\n"
print "... y vuelve a lanzarme."
exit
}

print "Averiguamos el ancho que ocupa nuestro texto"
err = gdImageStringFT("", brect, 0, TIPO_LETRA, TAM_LETRA, 0.0, 0, 0, txt)
if (err) {
print err
print "\nEl tipo de letra Greywolf Glyphs está en:"
print "http://greywolf.critter.net/fonts.htm"
exit
}
ancho = brect[2]-brect[6] + MARGEN

print "Averiguamos el trazo más alto y el más bajo del tipo de letra"
err = gdImageStringFT("", brect, 0, TIPO_LETRA, TAM_LETRA, 0.0, 0, 0, "|ÑILMgf_q")
alto = brect[3]-brect[7] + MARGEN
base = -brect[7]

print "Creamos una imagen, del tamaño de nuestro texto"
im = gdImageCreateTrueColor(ancho, alto)

print "Definimos el color marrón"
marron = gdImageColorAllocate(im, 204, 153, 51)

print "Rellenamos de marrón"
gdImageFilledRectangle(im, 0, 0, ancho, alto, marron)

print "Definimos el color lila"
lila = gdImageColorAllocate(im, 128, 0, 255)

print "Dibujamos el texto en lila"
x = MARGEN/2
y = base + MARGEN/2
err=gdImageStringFT(im, brect, lila, TIPO_LETRA, TAM_LETRA, 0.0, x, y, txt)

print "Guardamos el resultado"
gdImagePngName(im, salida)

print "Destruímos la imagen"
gdImageDestroy(im)

print "¡Eso es todo, amigos!"
}


Luego invocamos el comando:
xgawk -f jeroglifico.awk -vtxt="Maravilloso" -vsalida=texto_egipcio.png

Y ya tenemos la imagen.

Bueno, la verdad es que la he recomprimido un poquito más (un 38%), con el comando:
pngcrush.exe -brute texto_egipcio.png texto_egipcio2.png

No hay comentarios:

Publicar un comentario