We are using TinyMce with image plugin. https://www.tinymce.com/docs/plugins/image/
This plugin by default adds image file dimensions, when width and height fields are left blank. Is there any way to prevent this using config? Or do I have to hack it?
It's not exactly the logic you wanted, but it could be a good work-around. You can change the size of the image when it is inserted into the textarea. The script sets the image width to a maximum of 1000px (you can adapt the algorithm to your needs)
selector: 'textarea',
setup: function (editor) {
editor.on('init', function(args) {
editor = args.target;
editor.on('NodeChange', function(e) {
if (e && e.element.nodeName.toLowerCase() == 'img') {
width = e.element.width;
height = e.element.height;
if (width > 1000) {
height = height / (width / 1000);
width = 1000;
}
tinyMCE.DOM.setAttribs(e.element, {'width': width, 'height': height});
}
});
});
}, ......
If you set the image_dimensions
option to false
the plugin no longer includes width and height when inserting an image:
https://www.tinymce.com/docs/plugins/image/#image_dimensions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With