Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tinymce, image resize, use css instead of <img width & height>

Tags:

html

css

tinymce

I use this wonderful tool, tinyMCE, for editing pages at my website. But i have a problem with the resizing of images.

Is it possible to change the way tinyMCE changes the size of the image? Now the software changes the width and height inside the ..

<img src="..." width="..." height="..." />

But this setting gets overridden by the CSS. (I have some general img settings in the CSS, width, height:auto, and centering on page.)

If the users define a size for the image, i want this new size to override the general css. But with the img parameter width & height. this is notpossible. CSS override their value.

So.

I want tinyMCE to change the size of the image by CSS. Is this possible?

ex:

<img src="..." style="width:...;height...;" />

(The size is set by draging the corner of an image to the size you want.. and not edited in html html code.)

Thanks for reading. Matte

like image 769
Easyrider Avatar asked Feb 17 '12 12:02

Easyrider


Video Answer


2 Answers

I bypassed this by adding a plugin in the project that handles the re-size event.

Just going to post it here in case someone ever needs it.

tinymce.PluginManager.add('imageresizing', function(editor, url) {

editor.on('ObjectResizeStart', function(e) {
    if (e.target.nodeName == 'IMG') {

        var selectedImage = tinymce.activeEditor.selection.getNode();
        tinymce.activeEditor.dom.setStyle(selectedImage,'width', e.width);
        tinymce.activeEditor.dom.setStyle(selectedImage,'height', e.height);

        selectedImage.removeAttribute('width');
        selectedImage.removeAttribute('height');
    }
});

});

Of course you need to add the plugin to tinyMCE which is beyond the scope of this question, but it's not hard at all.

like image 114
drayn Avatar answered Nov 15 '22 00:11

drayn


To solve the problem of getting the default image insert size to fit the container, i used

content_style: 'img {max-width: 100%;}'

Inside the tinymce.init({

like image 29
Spinstaz Avatar answered Nov 14 '22 23:11

Spinstaz