<?php

$text='<p>
  <img';
$fulltext='<p>
  <img ...... >текст</p>';
        
echo preg_replace('/<p>\s*<img/','<p class="image"><img', $fulltext); 