Dynamically add images to article body
To accomplish this you need to edit the body field before rendering. There are 2 ways of doing this.

1) Using the node template file
In case of an article the template file would be node--article.tpl.php. Here is some sample code to edit the body field and include an ad after 4 paragraphs. The node--article.tpl.php file can be edited to make the following change.Here is the quick reference to theme pages in drupal.

 &lt;?php
       $array = explode("&lt;p&gt;", render($content['body']));
       $array_size = sizeof($array);
       if($array_size &lt; 5 ){
         $array[array_size-1] = $array[array_size-1]. $ad;
       }else{
         $array[4] = $array[4]. $ad;
       }
       $content['body'] = implode("", $array);
       print render($content['body']);
    ?&gt;


instead of rendering the body using &lt;?php print render($content['body']); ?&gt;

2) Using the hook_node_view.

This node gets invoked before the node gets rendered. You can include your logic to edit the body field based on your requirement in this hook. I am assuming you have some idea of implementing hooks in your custom module. Refer to this link for more details of this hook.