Starting with version 4.1, CKEditor offers the so-called Content Transformations and already defines some of them. If you restrict in config.allowedContent that you do not want to have width and height styles in <img> , then the editor will automatically convert the styles to attributes. For instance:
CKEDITOR.replace( 'editor1', { allowedContent: 'img[!src,alt,width,height]{float};' + // Note no {width,height} 'h1 h2 div' } );
then
<p><img alt="Saturn V carrying Apollo 11" class="left" src="assets/sample.jpg" style="height:250px; width:200px" /></p>
becomes output:
<p><img alt="Saturn V carrying Apollo 11" height="250" src="assets/sample.jpg" width="200" /></p>
and, I believe, it completely solves your problem.
source share