ported tito's core.image implementation; this depends on #1990