Migrated thumbnail generation code from filmstrip.js.