Cleaned up writeTextToImage