Reworked image handling. Much more efficient but doesn't work on libreoffice.