find : <img\s[^>]*\K(?<!/)>
replace: />
PHP Old test case using preg_replace() -
$xhtml = '<img src="myfile.png" alt="MyiMage" title="MyImage" border="0" >';
$str = preg_replace( '~<img\s[^>]*\K(?<!/)>~', "/>", $xhtml );
print $xhtml. "\n";
print $str;
Edit - Due to a downvote, I will amend the regex.
This is for the purist out there that think html/xhtml/xml should be parsed with regex.
To the OP - The original regex is easier to understand (and probably better!).
PHP New test case
$xhtml = '<img src="myfile.png" alt="MyiMage" title="MyImage" border="0" >';
$str = preg_replace( '~(?s)<img(?=\s|>)(?>(?:".*?"|\'.*?\'|[^>]*?)+\K>)(?<!/>)~', "/>", $xhtml );
print $xhtml. "\n";
print $str;
Output >>
<img src="myfile.png" alt="MyiMage" title="MyImage" border="0" >
<img src="myfile.png" alt="MyiMage" title="MyImage" border="0" />
New Regex explained
# '~(?s)<img(?=\s|>)(?>(?:".*?"|\'.*?\'|[^>]*?)+\K>)(?<!/>)~'
(?s) # Dot-All modifier
<img # 'img' tag
(?= \s | > ) # Assert followed by a whitespace or closing tag
(?> # Atomic magic -
(?: # Do this many times
" .*? " # Anything in double quotes
| ' .*? ' # Anything in single quotes
| [^>]*? # Least amount of non '>' chars as possible
)+
\K # \K, don't include up to here in the match output
> # Finally, the closing '>', the only character in match output
)
(?<! /> ) # Assert that tag was not closed