ckeditor5 - Insert and resize multiple inline images programmatically

Viewed 31

My goal is to make functionality that inserts N (chosen by user) inline images into a block (where N is greater than 2) and sets calculated width for each of them in order to make them all the same height.

Visual representation: link to image

In documentation I didn't find how to make it programmatically. Do I miss something?

If I select manually an image, then apply the command:

editor.execute( 'resizeImage', { width: '25%' } )

... the resizing is OK.

But if I set the height while inserting an image:

editor.model.change( writer => {
    let oImageElement = writer.createElement( 'imageInline', {
        src: sFile,
        linkHref: sLink,
        height: '25%'
    });
});

... it doesn't work.

Any idea how to achieve the desired result?


UPDATE (23 Sep 2022):

The same day I published the question here, I found a workaround by inserting html fragment as described here:

https://ckeditor.com/docs/ckeditor5/latest/support/faq.html#how-to-get-the-editor-instance-object-from-the-dom-element

But I am curious if anyone have a solution or actual answer to the question.

0 Answers
Related