1
votes

Redactor adding style attribute to the img tag while resizing

<img src="image_url" style="width: 189.00884955752213px; height: 118px;" >

This inline css is not affecting the image size when viewing in Outlook desktop app.

After doing some research I found that Outlook will show the image in required size only if the size is specified in the image tag with width & height attributes.

And the width value in style attribute generated by Redactor also not integer 189.00884955752213px.

How to fix these two issues

1

1 Answers

1
votes

I resolved the issue using the syncBeforeCallback method to make sure the image also had the width attribute for outlook

        syncBeforeCallback: function (html)
        {
            // set image width as attribute (for outlook)
            var $html = $('<div/>').html(html);
            $html.find('img').each(function copyImageCssWidthToAttribute() {
                var width = parseInt($(this).css('width'));
                if (width > 0) {
                    $(this).attr('width', width);
                }
            });
            html = $html.html();
            return html;
        },

I didn't find any case where the height was defined.