encode and decode images