You can use preg_match_all to get the width and height from style and then add these attributes using php str_replace. regular expression to match the width height would look like this: height:(.*?);width:(.*?);
$text = "<p>This is a paragraph with an image <img src='/url-to-img.jpg' style='height:100px;width:30px;float:right;'></p>
<p>This is another paragraph with an image <img src='/url-to-img.jpg' style='margin:10px;height:100px;width:30px;float:left;'></p>";
preg_match_all("/<img.*>/",$text,$out);
foreach($out as $t1)
{
foreach($t1 as $img)
{
preg_match("/.*height:(.*?);width:(.*?);.*/",$img,$out2);
$height = $out2[1];
$width = $out2[2];
$text = str_replace($out2[0],str_replace("<img","<img width='" . $width . "' height='" . $height . "'",$out2[0]),$text);
}
}
echo $text;