I found the answer to my question with help from Adobe Technology Partners.
I've got a working way to dynamically generate IDML with pictures.
IDML is a zip file which contains other files. This is a simple example of a working IDML file (structure).
The first file in an .idml (zipped) file is named:
mimetype
It must contain:
application/vnd.adobe.indesign-idml-package
The next file in an .idml (zipped) file is named:
designmap.xml
Here is an example of a working designmap.xml file:
<?xml version="1.0" encoding="utf-8"?><?aid style="50" type="document" readerVersion="6.0" featureSet="257"?>
<Document xmlns:idPkg="http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging" DOMVersion="6.0" Self="d">
<idPkg:Spread src="Spreads/Spread_2176.xml"/>
<idPkg:Story src="Stories/Story_2214.xml"/>
<idPkg:Story src="Stories/Story_2176.xml"/>
<idPkg:Story src="Stories/Story_asset_230.xml"/>
<idPkg:Story src="Stories/Story_asset_231.xml"/>
</Document>
Next in this example the .idml (zipped) are two folders:
Spreads
Stories
In this example the Spreads folder contains a single Spread_2227.xml document. Here is the contents of Spread_2227.xml:
<?xml version="1.0" encoding="utf-8"?>
<idPkg:Spread xmlns:idPkg="http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging" DOMVersion="6.0">
<Spread Self="spread_2214" PageCount="1" BindingLocation="0" >
<Page Self="Page_1" GeometricBounds="0 0 792 559" Name="headline for this story" >
<TextFrame Self="textframe_2214" ParentStory="story_2214" ContentType="TextType" >
<Properties>
<PathGeometry>
<GeometryPathType PathOpen="false">
<PathPointArray>
<PathPoint Anchor="41 41" LeftDirection="41 41" RightDirection="41 41"/>
<PathPoint Anchor="41 191" LeftDirection="41 191" RightDirection="41 191"/>
<PathPoint Anchor="559 191" LeftDirection="559 191" RightDirection="559 191"/>
<PathPoint Anchor="559 41" LeftDirection="559 41" RightDirection="559 41"/>
</PathPointArray>
</GeometryPathType>
</PathGeometry>
</Properties>
</TextFrame>
</Page>
</Spread>
<Spread Self="spread_2176" PageCount="1" BindingLocation="0" >
<Page Self="Page_2" GeometricBounds="0 0 792 559" Name="headline of story 2176" >
<TextFrame Self="textframe_2176" ParentStory="story_2176" ContentType="TextType" >
<Properties>
<PathGeometry>
<GeometryPathType PathOpen="false">
<PathPointArray>
<PathPoint Anchor="41 41" LeftDirection="41 41" RightDirection="41 41"/>
<PathPoint Anchor="41 191" LeftDirection="41 191" RightDirection="41 191"/>
<PathPoint Anchor="559 191" LeftDirection="559 191" RightDirection="559 191"/>
<PathPoint Anchor="559 41" LeftDirection="559 41" RightDirection="559 41"/>
</PathPointArray>
</GeometryPathType>
</PathGeometry>
</Properties>
</TextFrame>
</Page>
</Spread>
</idPkg:Spread>
In this example the Stories folder contains for xml documents. Story_2176.xml, Story_2214.xml,Story_asset_231.xml, Story_asset_230.xml Here is the contents of Stories folder:
Headline: headline of story 2176, rank: null, word count: 5, photos: 0
body content of this story.</Content>
</Story>
</idPkg:Story>
<?xml version="1.0" encoding="utf-8"?>
<idPkg:Story xmlns:idPkg="http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging" DOMVersion="6.0">
<Story Self="story_2176">
<Content>Headline: headline of story 2176, rank: null, word count: 5, photos: 0
body content of this story.</Content>
</Story>
</idPkg:Story>
<?xml version="1.0" encoding="utf-8"?>
<idPkg:Story xmlns:idPkg="http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging" DOMVersion="6.0">
<Story Self="cutline_231">
<Content>002</Content>
</Story>
</idPkg:Story>
<?xml version="1.0" encoding="utf-8"?>
<idPkg:Story xmlns:idPkg="http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging" DOMVersion="6.0">
<Story Self="cutline_230">
<Content>013</Content>
</Story>
</idPkg:Story>