Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyMce image plugin default dimensions

Tags:

tinymce

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?

like image 532
Filip Witkowski Avatar asked Sep 14 '25 21:09

Filip Witkowski


2 Answers

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});
        }
        });
    });
}, ......
like image 164
robotu Avatar answered Sep 17 '25 20:09

robotu


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

like image 27
Michael Fromin Avatar answered Sep 17 '25 18:09

Michael Fromin