How to scan Writer document and insert comments after image using a macro?

I have a Writer Document with images and text below.

I want to scan Writer Document, find images and text after. Cut this text and place it in the comments for the image above the cut text. All of this using a macro.