freezedryer icon indicating copy to clipboard operation
freezedryer copied to clipboard

Time Lapse features.

Open typesupply opened this issue 5 years ago • 0 comments

It would be nice to be able to generate a time-lapse video or set of images depecting the evolution of a glyph or string of glyphs.

Some code from @letterror:

# dig into the freezedryer archive
import os
import drawBot as ctx

g = CurrentGlyph()
f = CurrentFont()

if f:
    archivePath = os.path.join(os.path.dirname(f.path), "archive")
    entries = [n for n in os.listdir(archivePath) if n[0] != '.']
    entries.sort()
    #entries.reverse()

    glyphs = []
    for date in entries:
        print("reading", date)
        entryPath = os.path.join(archivePath, date)
        fileName = os.path.basename(f.path)
        entryUFOPath = os.path.join(entryPath, fileName)
        if os.path.exists(entryUFOPath):
            entryUFO = RFont(entryUFOPath, showUI=False)
            if g.name in entryUFO:
                g = entryUFO[g.name]
                glyphs.append((date, g))
            else:
                glyphs.append((date, None))
            entryUFO.close()
    if glyphs:
        ctx.newDrawing()
        ctx.size(500,500)
        first = True
        for date, g in glyphs:
            print('glyph', g.name, 'from', date)
            if not first:
                ctx.newPage()
            ctx.save()
            ctx.fill(1)
            ctx.rect(0,0,ctx.width(), ctx.height())
            ctx.fill(0.5)
            ctx.font("Menlo Regular")
            ctx.fontSize(10)
            ctx.text(date, (10, 10))
            s = ctx.height()/f.info.unitsPerEm
            if g is not None:
                ctx.translate(ctx.width()*.5,0)
                ctx.scale(s)
                ctx.translate(-.5*g.width, -f.info.descender)
                ctx.fill(0)
                ctx.stroke(None)
                ctx.drawGlyph(g)
            ctx.restore()
            first = False
    moviePath = "%s_%s.mp4" % (os.path.splitext(fileName)[0], g.name)
    print('saving to', moviePath)
    ctx.saveImage(moviePath)

typesupply avatar Aug 18 '20 12:08 typesupply