You could tie into the saveRichTextContent Pipeline. You could then parse the html that has been entered, and find all the images and strip out the width and height, which is a good practice if you have a responsive site.
Patch:
<configuration>
<sitecore>
<pipelines>
<saveRichTextContent>
<processor type="Component.Pipelines.FormatImagesRichText, Component"></processor>
</saveRichTextContent>
</pipelines>
</sitecore>
</configuration>
Then the source of the pipeline would look like this:
namespace Component.Pipelines
{
public class FormatImagesRichText
{
public void Process(SaveRichTextContentArgs args)
{
args.Content = FormatImages(args.Content);
}
private string FormatImages(string content)
{
var doc = new HtmlDocument();
doc.LoadHtml(content);
if (doc == null || !doc.DocumentNode.InnerHtml.Contains("img"))
return content;
foreach (var img in doc.DocumentNode.Descendants("img"))
{
// Remove Image Width/Height Information
HtmlNode imgNode = img;
imgNode.Attributes.Remove("height");
imgNode.Attributes.Remove("width");
}
return doc.DocumentNode.OuterHtml;
}
}
}
Edit: As an added note, if you are using a frontend system, such as Bootstrap, you can also add any relevant classes as follows:
foreach (var img in doc.DocumentNode.Descendants("img"))
{
// Remove Image Width/Height Information
HtmlNode imgNode = img;
imgNode.Attributes.Remove("height");
imgNode.Attributes.Remove("width");
if(imgNode.Attributes.Any(a => a.Name == "class"))
{
imgNode.Attributes["class"].Value += " img-fluid";
}
else
{
imgNode.Attributes.Add("class", "img-fluid");
}
}