|
@@ -7,17 +7,17 @@ category: features
|
|
|
|
|
|
|
|
The [`@ckeditor/ckeditor5-image`](https://www.npmjs.com/package/@ckeditor/ckeditor5-image) package contains multiple plugins that implement various image-related features:
|
|
The [`@ckeditor/ckeditor5-image`](https://www.npmjs.com/package/@ckeditor/ckeditor5-image) package contains multiple plugins that implement various image-related features:
|
|
|
|
|
|
|
|
-* {@link module:image/image~Image} implements basic support for images.
|
|
|
|
|
-* {@link module:image/imagetoolbar~ImageToolbar} adds the image feature's contextual toolbar.
|
|
|
|
|
-* {@link module:image/imagecaption~ImageCaption} adds support for captions.
|
|
|
|
|
-* {@link module:image/imagestyle~ImageStyle} adds support for image styles.
|
|
|
|
|
|
|
+* {@link module:image/image~Image} implements [basic support for images](#base-image-support).
|
|
|
|
|
+* {@link module:image/imagetoolbar~ImageToolbar} adds the image feature's [contextual toolbar](#image-contextual-toolbar).
|
|
|
|
|
+* {@link module:image/imagecaption~ImageCaption} adds support for [captions](#image-captions).
|
|
|
|
|
+* {@link module:image/imagestyle~ImageStyle} adds support for [image styles](#image-styles).
|
|
|
* {@link module:image/imagetextalternative~ImageTextAlternative} adds support for adding text alternative.
|
|
* {@link module:image/imagetextalternative~ImageTextAlternative} adds support for adding text alternative.
|
|
|
-* {@link module:image/imageupload~ImageUpload} adds support for uploading dropped or pasted images (see: {@link features/image-upload Image upload}).
|
|
|
|
|
-* {@link module:image/imageresize~ImageResize} adds support for resizing images.
|
|
|
|
|
-* {@link module:link/linkimage~LinkImage} adds support for linking images.
|
|
|
|
|
|
|
+* {@link module:image/imageupload~ImageUpload} adds support for {@link features/image-upload uploading dropped or pasted images}.
|
|
|
|
|
+* {@link module:image/imageresize~ImageResize} adds support for [resizing images](#resizing-images).
|
|
|
|
|
+* {@link module:link/linkimage~LinkImage} adds support for [linking images](#linking-images).
|
|
|
|
|
|
|
|
<info-box info>
|
|
<info-box info>
|
|
|
- All features listed above except the image resize and image linking are enabled by default in all WYSIWYG editor builds.
|
|
|
|
|
|
|
+ All features listed above except image resizing and image linking are enabled by default in all CKEditor 5 WYSIWYG editor builds.
|
|
|
|
|
|
|
|
Check the documentation of each subfeature to learn more about it.
|
|
Check the documentation of each subfeature to learn more about it.
|
|
|
</info-box>
|
|
</info-box>
|
|
@@ -46,7 +46,7 @@ You can see the demo of a WYSIWYG editor with the base image feature enabled bel
|
|
|
|
|
|
|
|
## Image contextual toolbar
|
|
## Image contextual toolbar
|
|
|
|
|
|
|
|
-The {@link module:image/imagetoolbar~ImageToolbar} plugin introduces a contextual toolbar for images. The toolbar appears when an image is selected and can be configured to contain any buttons you want. Usually, these will be image-related options such as the text alternative (which is introduced by the base image plugin) button and [image styles buttons](#image-styles).
|
|
|
|
|
|
|
+The {@link module:image/imagetoolbar~ImageToolbar} plugin introduces a contextual toolbar for images. The toolbar appears when an image is selected and can be configured to contain any buttons you want. Usually, these will be image-related options such as the text alternative button (a feature introduced by the base image plugin) and [image styles buttons](#image-styles).
|
|
|
|
|
|
|
|
See a demo of a WYSIWYG editor with the contextual toolbar enabled:
|
|
See a demo of a WYSIWYG editor with the contextual toolbar enabled:
|
|
|
|
|
|
|
@@ -70,11 +70,11 @@ The {@link module:image/imagecaption~ImageCaption} plugin adds support for image
|
|
|
```html
|
|
```html
|
|
|
<figure class="image">
|
|
<figure class="image">
|
|
|
<img src="..." alt="...">
|
|
<img src="..." alt="...">
|
|
|
- <figcaption>Caption goes here...</figcaption>
|
|
|
|
|
|
|
+ <figcaption>A caption goes here...</figcaption>
|
|
|
</figure>
|
|
</figure>
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-By default, if the image caption is empty, the `<figcaption>` element is not visible to the user. You can click the image to reveal the caption. See the demo below:
|
|
|
|
|
|
|
+By default, if the image caption is empty, the `<figcaption>` element is not visible to the user. You can click the image to reveal the caption field and write one. See the demo below:
|
|
|
|
|
|
|
|
{@snippet features/image-caption}
|
|
{@snippet features/image-caption}
|
|
|
|
|
|
|
@@ -84,23 +84,23 @@ See the {@link features/image-upload Image upload} guide.
|
|
|
|
|
|
|
|
## Responsive images
|
|
## Responsive images
|
|
|
|
|
|
|
|
-Support for responsive images in CKEditor 5 is brought by the {@link features/easy-image Easy Image} feature without any additional configuration. Learn more how to use the feature in your project in the {@link features/easy-image#responsive-images Easy Image integration} guide.
|
|
|
|
|
|
|
+Support for responsive images in CKEditor 5 is brought by the {@link features/easy-image Easy Image} feature without any additional configuration. Refer to the {@link features/easy-image#responsive-images Easy Image integration} guide to learn how to use the feature in your project.
|
|
|
|
|
|
|
|
## Image styles
|
|
## Image styles
|
|
|
|
|
|
|
|
-In simple integrations it is enough to let the user insert images, set their text alternative and the editor's job is done. An example of such a simple solution are e.g. [GitHub](https://github.com) comments. The styling of the images (for example, their maximum width and margins) is controlled by GitHub through stylesheets.
|
|
|
|
|
|
|
+In simple integrations it is enough to let the user insert images, set their text alternative and the editor's job is done. An example of such a simple solution are, for example, [GitHub](https://github.com/) comments. The styling of the images (for example, their maximum width and margins) is controlled by GitHub through stylesheets.
|
|
|
|
|
|
|
|
-In more advanced scenarios, the user may need to be able to decide whether the image should take the whole width (if it is the article's main photo) or it should take, for example, 50% of the width and be pulled out of the content (so called "pulled images"). Various integration scenarios require different types of images to be used.
|
|
|
|
|
|
|
+In more advanced scenarios, the user may need to be able to decide about the image's width. Should it take up the whole width (if it is the article's main photo) or should it take up, for example, 50% of the width and be pulled out of the content (so called "pulled images")? Various integration scenarios require different types of images to be used.
|
|
|
|
|
|
|
|
-Finally, in certain situations, the user should be able to granularly control how an image is presented so they should be able to set the size and alignment separately.
|
|
|
|
|
|
|
+Finally, in certain situations, the user should be able to granularly control how an image is presented thanks to the ability to set the size and alignment separately.
|
|
|
|
|
|
|
|
-The {@link module:image/imagestyle~ImageStyle} feature solves the last two scenarios. The former is handled by so-called ["semantical styles"](#semantical-styles) and the latter by ["presentational styles"](#presentational-styles) in combination with [image resize](#resizing-images).
|
|
|
|
|
|
|
+The {@link module:image/imagestyle~ImageStyle} feature solves the last two scenarios. The former is handled by so-called ["semantical styles"](#semantical-styles) and the latter by ["presentational styles"](#presentational-styles) in combination with the [image resize](#resizing-images) feature.
|
|
|
|
|
|
|
|
The available image styles can be configured using the {@link module:image/image~ImageConfig#styles `config.image.styles`} option. Respective buttons should also be added to the image toolbar via {@link module:image/image~ImageConfig#toolbar `config.image.toolbar`}.
|
|
The available image styles can be configured using the {@link module:image/image~ImageConfig#styles `config.image.styles`} option. Respective buttons should also be added to the image toolbar via {@link module:image/image~ImageConfig#toolbar `config.image.toolbar`}.
|
|
|
|
|
|
|
|
### Semantical styles
|
|
### Semantical styles
|
|
|
|
|
|
|
|
-A semantical style let the user choose from a predefined "types" of images. The user is not able to set the image border, alignment, margins, width, etc. separately. Instead, they can pick one of the styles defined by the developer who prepared the WYSIWYG editor integration. This gives the developer control over how the users style images and makes the user's life easier by setting multiple properties at once.
|
|
|
|
|
|
|
+A semantical style lets the user choose from predefined "types" of images. The user is not able to set the image border, alignment, margins, width, etc. separately. Instead, they can pick one of the styles defined by the developer who prepared the WYSIWYG editor integration. This gives the developer control over how the users style their images and makes the user's life easier by setting multiple properties at once.
|
|
|
|
|
|
|
|
A style is applied to the image in form of a class. By default, CKEditor 5 is configured to support two default semantical styles: **"full width"** (which does not apply any class — it is the default style) and **"side image"** (which applies the `image-style-side` class).
|
|
A style is applied to the image in form of a class. By default, CKEditor 5 is configured to support two default semantical styles: **"full width"** (which does not apply any class — it is the default style) and **"side image"** (which applies the `image-style-side` class).
|
|
|
|
|
|
|
@@ -117,14 +117,14 @@ A side image:
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
<info-box>
|
|
<info-box>
|
|
|
- The actual styling of the images is the integrator's job. CKEditor 5 WYSIWYG editor comes with some default styles, but they will only be applied to images inside the editor. The integrator needs to style them appropriately on the target pages.
|
|
|
|
|
|
|
+ The actual styling of the images is the integrator's job. CKEditor 5 WYSIWYG editor comes with some default styles, but they will only be applied to the images inside the editor. The integrator needs to style them appropriately on the target pages.
|
|
|
|
|
|
|
|
You can find the source of the default styles applied by the editor here: [`ckeditor5-image/theme/imagestyle.css`](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-image/theme/imagestyle.css).
|
|
You can find the source of the default styles applied by the editor here: [`ckeditor5-image/theme/imagestyle.css`](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-image/theme/imagestyle.css).
|
|
|
|
|
|
|
|
Read more about {@link builds/guides/integration/content-styles styling the content of the editor}.
|
|
Read more about {@link builds/guides/integration/content-styles styling the content of the editor}.
|
|
|
</info-box>
|
|
</info-box>
|
|
|
|
|
|
|
|
-Below you can see a demo of the WYSIWYG editor with the semantical image styles. The "full" and "side" styles are the default value of {@link module:image/image~ImageConfig#styles `config.image.styles`} so you do not need to set it.
|
|
|
|
|
|
|
+Below you can find a demo of the WYSIWYG editor with the semantical image styles. The "full" and "side" styles are the default value of {@link module:image/image~ImageConfig#styles `config.image.styles`} so you do not need to set it.
|
|
|
|
|
|
|
|
```js
|
|
```js
|
|
|
ClassicEditor
|
|
ClassicEditor
|
|
@@ -138,7 +138,7 @@ ClassicEditor
|
|
|
'imageTextAlternative'
|
|
'imageTextAlternative'
|
|
|
],
|
|
],
|
|
|
|
|
|
|
|
- // The default value,
|
|
|
|
|
|
|
+ // The default value.
|
|
|
styles: [
|
|
styles: [
|
|
|
'full',
|
|
'full',
|
|
|
'side'
|
|
'side'
|
|
@@ -149,12 +149,12 @@ ClassicEditor
|
|
|
.catch( ... );
|
|
.catch( ... );
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-See the result below. You can change the styles of images through the image's contextual toolbar.
|
|
|
|
|
|
|
+See the result in the WYSIWYG editor below. You can change the style of an image through the image's contextual toolbar.
|
|
|
|
|
|
|
|
{@snippet features/image-style}
|
|
{@snippet features/image-style}
|
|
|
|
|
|
|
|
<info-box hint>
|
|
<info-box hint>
|
|
|
-Try to understand what use cases the system needs to support and define semantic options accordingly. Defining useful and clear styles is one of the steps towards a good user experience and clear, portable output. For example, the "side image" style can be displayed as a floated image on wide screens and as a normal image on low resolution screens (e.g. mobile browsers).
|
|
|
|
|
|
|
+ Try to understand what use cases the system needs to support and define semantic options accordingly. Defining useful and clear styles is one of the steps towards a good user experience and clear, portable output. For example, the "side image" style can be displayed as a floated image on wide screens and as a normal image on low resolution screens (e.g. mobile browsers).
|
|
|
</info-box>
|
|
</info-box>
|
|
|
|
|
|
|
|
<info-box warning>
|
|
<info-box warning>
|
|
@@ -169,6 +169,14 @@ Presentational styles do not add any special meaning to the content. They direct
|
|
|
|
|
|
|
|
Currently, the available presentational styles are "align center", "align left" and "align right".
|
|
Currently, the available presentational styles are "align center", "align left" and "align right".
|
|
|
|
|
|
|
|
|
|
+<info-box warning>
|
|
|
|
|
+ Presentational image styles should be combined with the optional [image resize feature](#resizing-images) as these features were designed to be used together. The image width is then controlled by the image resize feature.
|
|
|
|
|
+
|
|
|
|
|
+ If you do not enable the image resize feature in your setup using the default presentational styles, your images will always take up 100% of the editor width so the alignment may not be visible.
|
|
|
|
|
+
|
|
|
|
|
+ If you do not want to enable image resizing, use [semantical image styles](#semantical-styles).
|
|
|
|
|
+</info-box>
|
|
|
|
|
+
|
|
|
```js
|
|
```js
|
|
|
ClassicEditor
|
|
ClassicEditor
|
|
|
.create( document.querySelector( '#editor' ), {
|
|
.create( document.querySelector( '#editor' ), {
|
|
@@ -178,10 +186,32 @@ ClassicEditor
|
|
|
'alignLeft', 'alignCenter', 'alignRight'
|
|
'alignLeft', 'alignCenter', 'alignRight'
|
|
|
],
|
|
],
|
|
|
|
|
|
|
|
- // You need to configure the image toolbar, too, so it shows the new style buttons.
|
|
|
|
|
|
|
+ // Configure the available image resize options.
|
|
|
|
|
+ resizeOptions: [
|
|
|
|
|
+ {
|
|
|
|
|
+ name: 'imageResize:original',
|
|
|
|
|
+ label: 'Original',
|
|
|
|
|
+ value: null
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: 'imageResize:50',
|
|
|
|
|
+ label: '50%',
|
|
|
|
|
+ value: '50'
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: 'imageResize:75',
|
|
|
|
|
+ label: '75%',
|
|
|
|
|
+ value: '75'
|
|
|
|
|
+ }
|
|
|
|
|
+ ],
|
|
|
|
|
+
|
|
|
|
|
+ // You need to configure the image toolbar, too, so it shows the new style
|
|
|
|
|
+ // buttons as well as the resize buttons.
|
|
|
toolbar: [
|
|
toolbar: [
|
|
|
'imageStyle:alignLeft', 'imageStyle:alignCenter', 'imageStyle:alignRight',
|
|
'imageStyle:alignLeft', 'imageStyle:alignCenter', 'imageStyle:alignRight',
|
|
|
'|',
|
|
'|',
|
|
|
|
|
+ 'imageResize',
|
|
|
|
|
+ '|',
|
|
|
'imageTextAlternative'
|
|
'imageTextAlternative'
|
|
|
]
|
|
]
|
|
|
}
|
|
}
|
|
@@ -192,6 +222,8 @@ ClassicEditor
|
|
|
|
|
|
|
|
The code sample above uses predefined presentational image styles: `'alignLeft'`, `'alignCenter'` and `'alignRight'`. They apply, respectively, the `.image-style-align-left`, `.image-style-align-center` and `.image-style-align-right` classes to the `<figure>` element.
|
|
The code sample above uses predefined presentational image styles: `'alignLeft'`, `'alignCenter'` and `'alignRight'`. They apply, respectively, the `.image-style-align-left`, `.image-style-align-center` and `.image-style-align-right` classes to the `<figure>` element.
|
|
|
|
|
|
|
|
|
|
+In addition to that, the sample is configured to use the [image resize feature](#resizing-images) with three {@link module:image/image~ImageConfig#resizeOptions resize options} available: `'imageResize:original'`, `'imageResize:50'` and `'imageResize:75'`. They allow you to set the image width in the editor to the original image size, 50% and 75%, respectively.
|
|
|
|
|
+
|
|
|
See the result below:
|
|
See the result below:
|
|
|
|
|
|
|
|
{@snippet features/image-style-presentational}
|
|
{@snippet features/image-style-presentational}
|
|
@@ -214,29 +246,29 @@ you can also define your own styles or modify the existing ones.
|
|
|
|
|
|
|
|
You can find advanced examples in the {@link module:image/image~ImageConfig#styles `config.image.styles`} configuration option documentation.
|
|
You can find advanced examples in the {@link module:image/image~ImageConfig#styles `config.image.styles`} configuration option documentation.
|
|
|
|
|
|
|
|
-<!-- TODO (live example)... -->
|
|
|
|
|
|
|
+<!-- TODO (live example)... not today, yet -->
|
|
|
|
|
|
|
|
## Resizing images
|
|
## Resizing images
|
|
|
|
|
|
|
|
-The [image styles](#image-styles) feature is meant to give the user the choice between a set of styling options provided by the system (so by the developer or administrator who created it). There are also scenarios where the user should be able to freely set the width of an image. And that is where the image resize feature comes to play.
|
|
|
|
|
|
|
+The [image styles](#image-styles) feature is meant to give the user a choice between a set of styling options provided by the system (i.e. by the developer or administrator who created it). There are also scenarios where the user should be able to freely set the width of an image. And that is where the image resize feature comes into play. It is implemented by the {@link module:image/imageresize~ImageResize} plugin.
|
|
|
|
|
|
|
|
-It is implemented by the {@link module:image/imageresize~ImageResize} plugin and enables four "resize handles" displayed over the selected image. The user can freely resize the image by dragging them. The feature can be configured to use either percentage (default) or pixel values.
|
|
|
|
|
|
|
+### Methods to resize images
|
|
|
|
|
|
|
|
-The plugin also gives you an ability to change the size of the image through the image toolbar. You can set an optional static configuration with {@link module:image/image~ImageConfig#resizeOptions} and choose whether you want to use a dropdown or set of the standalone buttons.
|
|
|
|
|
|
|
+The editor offers different ways to resize images either by using "resize handles" or by using dedicated UI components — either a dropdown or standalone buttons.
|
|
|
|
|
|
|
|
-### Methods to resize images
|
|
|
|
|
|
|
+The {@link module:image/imageresize~ImageResize} plugin enables the four resize handles displayed over the selected image. The user can freely resize the image by dragging them. The feature can be configured to use either percentage (default) or pixel values.
|
|
|
|
|
|
|
|
-The editor offers different ways to resize images either by using resize handles or by using dedicated UI components.
|
|
|
|
|
|
|
+The plugin also gives you an ability to change the size of the image through the on-click image toolbar. You can set an optional static configuration with {@link module:image/image~ImageConfig#resizeOptions} and choose whether you want to use a dropdown or a set of standalone buttons.
|
|
|
|
|
|
|
|
-#### Using handles
|
|
|
|
|
|
|
+#### Using resize handles
|
|
|
|
|
|
|
|
-In this case, the user is able to resize images via dragging square handles displayed in each corner of the image. Once [image resizing was enabled](#enabling-image-resizing), this option does not require any additional configuration.
|
|
|
|
|
|
|
+In this case, the user is able to resize images by dragging square handles displayed in each corner of the image. Once [image resizing is enabled](#enabling-image-resizing), this option does not require any additional configuration.
|
|
|
|
|
|
|
|
{@snippet features/image-resize}
|
|
{@snippet features/image-resize}
|
|
|
|
|
|
|
|
-You can configure the editor for resizing images by handles in two different ways:
|
|
|
|
|
|
|
+You can configure resizing images by handles in two different ways in the CKEditor 5 WYSIWYG editor:
|
|
|
|
|
|
|
|
-- By installing the {@link module:image/imageresize~ImageResize} plugin, which contains **all** needed features (`ImageResizeEditing`, `ImageResizeHandles`, `ImageResizeButtons`).
|
|
|
|
|
|
|
+* Either by installing the {@link module:image/imageresize~ImageResize} plugin, which contains **all** needed features (`ImageResizeEditing`, `ImageResizeHandles`, `ImageResizeButtons`):
|
|
|
|
|
|
|
|
```js
|
|
```js
|
|
|
import Image from '@ckeditor/ckeditor5-image/src/image';
|
|
import Image from '@ckeditor/ckeditor5-image/src/image';
|
|
@@ -251,7 +283,7 @@ ClassicEditor
|
|
|
.catch( ... );
|
|
.catch( ... );
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-- Or by installing the combination of {@link module:image/imageresize/imageresizeediting~ImageResizeEditing} and {@link module:image/imageresize/imageresizehandles~ImageResizeHandles} plugins.
|
|
|
|
|
|
|
+* Or by installing the combination of {@link module:image/imageresize/imageresizeediting~ImageResizeEditing} and {@link module:image/imageresize/imageresizehandles~ImageResizeHandles} plugins:
|
|
|
|
|
|
|
|
```js
|
|
```js
|
|
|
import Image from '@ckeditor/ckeditor5-image/src/image';
|
|
import Image from '@ckeditor/ckeditor5-image/src/image';
|
|
@@ -269,11 +301,11 @@ ClassicEditor
|
|
|
|
|
|
|
|
Both ways enable resize handles by default.
|
|
Both ways enable resize handles by default.
|
|
|
|
|
|
|
|
-#### Using the dropdown
|
|
|
|
|
|
|
+#### Using resize dropdown
|
|
|
|
|
|
|
|
-In this case, the user is able to choose from a set of predefined options. These options can be displayed in the image toolbar in form of a dropdown.
|
|
|
|
|
|
|
+In this case, the user is able to choose from a set of predefined options. These options can be displayed in form of a dropdown in the image toolbar available after the user clicks the image.
|
|
|
|
|
|
|
|
-To use this option, you need to [enable image resizing](#enabling-image-resizing) and configure the available {@link module:image/image~ImageConfig#resizeOptions resize options}.
|
|
|
|
|
|
|
+To use this option, you need to [enable image resizing](#enabling-image-resizing) and configure the available {@link module:image/image~ImageConfig#resizeOptions resize options}. Then add the dropdown to the image toolbar configuration.
|
|
|
|
|
|
|
|
```js
|
|
```js
|
|
|
const imageConfiguration = {
|
|
const imageConfiguration = {
|
|
@@ -298,13 +330,15 @@ const imageConfiguration = {
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
+Try out the live demo of the resize dropdown available in the image toolbar below.
|
|
|
|
|
+
|
|
|
{@snippet features/image-resize-buttons-dropdown}
|
|
{@snippet features/image-resize-buttons-dropdown}
|
|
|
|
|
|
|
|
-#### Using standalone buttons
|
|
|
|
|
|
|
+#### Using standalone resize buttons
|
|
|
|
|
|
|
|
-In this case, the resize options are displayed in form of separate buttons. The benefit of this solution is the smoothest UX as the user needs just one click to resize an image.
|
|
|
|
|
|
|
+In this case, the resize options are displayed in the form of separate buttons. The benefit of this solution is the smoothest UX as the user needs just one click to resize an image.
|
|
|
|
|
|
|
|
-To use this option, you need to [enabling image resizing](#enabling-image-resizing) and configure the available {@link module:image/image~ImageConfig#resizeOptions resize options}.
|
|
|
|
|
|
|
+To use this option, you need to [enable image resizing](#enabling-image-resizing) and configure the available {@link module:image/image~ImageConfig#resizeOptions resize options}. Then add appropriate buttons to the image toolbar configuration.
|
|
|
|
|
|
|
|
```js
|
|
```js
|
|
|
const imageConfiguration = {
|
|
const imageConfiguration = {
|
|
@@ -333,12 +367,17 @@ const imageConfiguration = {
|
|
|
]
|
|
]
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
+Try out the live demo of the individual resize buttons available in the image toolbar below:
|
|
|
|
|
|
|
|
{@snippet features/image-resize-buttons}
|
|
{@snippet features/image-resize-buttons}
|
|
|
|
|
|
|
|
### Disabling image resize handles
|
|
### Disabling image resize handles
|
|
|
|
|
|
|
|
-If, for some reason, you want to configure the editor in such a way that images can be resized only by buttons you can do so by omitting the {@link module:image/imageresize/imageresizehandles~ImageResizeHandles `ImageResizeHandles`} plugin. As a result, plugins setup should look like this: `plugins: [ 'ImageResizeEditing', 'ImageResizeButtons', ... ]` as opposed to `plugins: [ 'ImageResize', ... ]`. It will enable resizing image feature only by means of the chosen UI ([dropdown](#using-the-dropdown) or [standalone buttons](#using-standalone-buttons)) in the image toolbar.
|
|
|
|
|
|
|
+If, for some reason, you want to configure the editor in such a way that images can be resized only by buttons, you can do so by omitting the {@link module:image/imageresize/imageresizehandles~ImageResizeHandles `ImageResizeHandles`} plugin.
|
|
|
|
|
+
|
|
|
|
|
+As a result, your plugin setup should look like this: `plugins: [ 'ImageResizeEditing', 'ImageResizeButtons', ... ]` as opposed to `plugins: [ 'ImageResize', ... ]`.
|
|
|
|
|
+
|
|
|
|
|
+This will enable the image resize feature only by means of the chosen UI: either a [dropdown](#using-resize-dropdown) or [standalone buttons](#using-standalone-resize-buttons)) in the image toolbar.
|
|
|
|
|
|
|
|
```js
|
|
```js
|
|
|
import Image from '@ckeditor/ckeditor5-image/src/image';
|
|
import Image from '@ckeditor/ckeditor5-image/src/image';
|
|
@@ -385,7 +424,7 @@ The image resize feature is not enabled by default in any of the editor builds.
|
|
|
|
|
|
|
|
### Markup and styling
|
|
### Markup and styling
|
|
|
|
|
|
|
|
-When you resize an image, the inline `width` style is used and the `<figure>` is assigned the `image_resized` class:
|
|
|
|
|
|
|
+When you resize an image, the inline `width` style is used and the `<figure>` element is assigned the `image_resized` class:
|
|
|
|
|
|
|
|
```html
|
|
```html
|
|
|
<figure class="image image_resized" style="width: 75%;">
|
|
<figure class="image image_resized" style="width: 75%;">
|
|
@@ -411,7 +450,7 @@ And the `max-width` gets overridden by the following rule:
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-Another concern when styling resized images is that by default, CKEditor 5 uses `display: table` on `<figure class="image">` to make it take the size of the `<img>` element inside it. Unfortunately, [browsers do not yet support using `max-width` and `width` on the same element if it is styled with `display: table`](https://stackoverflow.com/questions/4019604/chrome-safari-ignoring-max-width-in-table/14420691#14420691). Therefore, `display: block` needs to be used when the image is resized:
|
|
|
|
|
|
|
+Another concern when styling resized images is that by default, CKEditor 5 uses `display: table` on `<figure class="image">` elements to make it take up the size of the `<img>` element inside it. Unfortunately, [browsers do not yet support using `max-width` and `width` on the same element if it is styled with `display: table`](https://stackoverflow.com/questions/4019604/chrome-safari-ignoring-max-width-in-table/14420691#14420691). Therefore, `display: block` needs to be used when the image is resized:
|
|
|
|
|
|
|
|
```css
|
|
```css
|
|
|
.ck-content .image.image_resized {
|
|
.ck-content .image.image_resized {
|
|
@@ -430,9 +469,9 @@ Another concern when styling resized images is that by default, CKEditor 5 uses
|
|
|
|
|
|
|
|
### Using pixels instead of percentage width
|
|
### Using pixels instead of percentage width
|
|
|
|
|
|
|
|
-Using percentage widths ensures that content stays responsive when displayed in different places than in the WYSIWYG editor. If the user made an image take 60% of the content's width in the editor, if you ever change the width of the target page (where this content is displayed), the image will still take 60% of that space. The same is true if the page is responsive and adjusts to the viewport's width.
|
|
|
|
|
|
|
+Using percentage widths ensures that the content stays responsive when displayed in places other than the WYSIWYG editor. When the user made an image take up, for example, 60% of the content's width in the editor, if you ever change the width of the target page (where this content is displayed), the image will still take up 60% of that space. The same is true if the page is responsive and adjusts to the viewport's width.
|
|
|
|
|
|
|
|
-If you configured the editor to use pixel values, the image could take, for example, too much space after you introduced a new layout for your website.
|
|
|
|
|
|
|
+If you configured the editor to use pixel values, the image could take up, for example, too much space after you introduced a new layout for your website.
|
|
|
|
|
|
|
|
However, there are cases where pixel values may be preferred. You can thus configure the editor to use them by setting the {@link module:image/image~ImageConfig#resizeUnit `config.image.resizeUnit`} option:
|
|
However, there are cases where pixel values may be preferred. You can thus configure the editor to use them by setting the {@link module:image/image~ImageConfig#resizeUnit `config.image.resizeUnit`} option:
|
|
|
|
|
|
|
@@ -447,16 +486,20 @@ ClassicEditor
|
|
|
.catch( ... );
|
|
.catch( ... );
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
+Check out the difference in the live demo below:
|
|
|
|
|
+
|
|
|
{@snippet features/image-resize-px}
|
|
{@snippet features/image-resize-px}
|
|
|
|
|
|
|
|
## Linking images
|
|
## Linking images
|
|
|
|
|
|
|
|
-The {@link module:link/linkimage~LinkImage} plugin adds support for linking images. Some use cases where this is needed are:
|
|
|
|
|
|
|
+The {@link module:link/linkimage~LinkImage} plugin adds support for linking images. Some use cases where this could be useful are:
|
|
|
|
|
|
|
|
* Linking to a high-resolution version of an image.
|
|
* Linking to a high-resolution version of an image.
|
|
|
* Using images as thumbnails linking to an article or product page.
|
|
* Using images as thumbnails linking to an article or product page.
|
|
|
* Creating banners linking to other pages.
|
|
* Creating banners linking to other pages.
|
|
|
|
|
|
|
|
|
|
+The image link can be added or edited via the image toolbar. An icon in top right corner of the image indicates the presence of a link.
|
|
|
|
|
+
|
|
|
```html
|
|
```html
|
|
|
<figure class="image">
|
|
<figure class="image">
|
|
|
<a href="...">
|
|
<a href="...">
|
|
@@ -465,6 +508,7 @@ The {@link module:link/linkimage~LinkImage} plugin adds support for linking imag
|
|
|
<figcaption>Image caption</figcaption>
|
|
<figcaption>Image caption</figcaption>
|
|
|
</figure>
|
|
</figure>
|
|
|
```
|
|
```
|
|
|
|
|
+Use the link icon in the image toolbar to access the edit options for links on image.
|
|
|
|
|
|
|
|
{@snippet features/image-link}
|
|
{@snippet features/image-link}
|
|
|
|
|
|
|
@@ -484,7 +528,7 @@ To add image features to your rich-text editor, install the [`@ckeditor/ckeditor
|
|
|
npm install --save @ckeditor/ckeditor5-image @ckeditor/ckeditor5-link
|
|
npm install --save @ckeditor/ckeditor5-image @ckeditor/ckeditor5-link
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-And add the plugins that you need to your plugin list. You also need to set the image toolbar items.
|
|
|
|
|
|
|
+Next add the plugins that you need to your plugin list. You also need to set the desired image toolbar items.
|
|
|
|
|
|
|
|
```js
|
|
```js
|
|
|
import Image from '@ckeditor/ckeditor5-image/src/image';
|
|
import Image from '@ckeditor/ckeditor5-image/src/image';
|
|
@@ -522,12 +566,12 @@ The {@link module:image/image~Image} plugin registers:
|
|
|
|
|
|
|
|
* The `'imageTextAlternative'` button.
|
|
* The `'imageTextAlternative'` button.
|
|
|
* The {@link module:image/imagetextalternative/imagetextalternativecommand~ImageTextAlternativeCommand `'imageTextAlternative'` command}
|
|
* The {@link module:image/imagetextalternative/imagetextalternativecommand~ImageTextAlternativeCommand `'imageTextAlternative'` command}
|
|
|
-* The {@link module:image/image/imageinsertcommand~ImageInsertCommand `'imageInsert'` command} which accepts a source (e.g. an URL) of an image to insert.
|
|
|
|
|
|
|
+* The {@link module:image/image/imageinsertcommand~ImageInsertCommand `'imageInsert'` command} that accepts a source (e.g. a URL) of an image to insert.
|
|
|
|
|
|
|
|
The {@link module:image/imagestyle~ImageStyle} plugin registers:
|
|
The {@link module:image/imagestyle~ImageStyle} plugin registers:
|
|
|
|
|
|
|
|
-* A button for each defined style — e.g. `'imageStyle:full'` and `'imageStyle:side'`.
|
|
|
|
|
-* The {@link module:image/imagestyle/imagestylecommand~ImageStyleCommand `'imageStyle'` command} which accepts a value based on the {@link module:image/image~ImageConfig#styles `image.styles`} configuration option (e.g. `'full'` and `'side'`):
|
|
|
|
|
|
|
+* A button for each defined style, for example: `'imageStyle:full'` and `'imageStyle:side'`.
|
|
|
|
|
+* The {@link module:image/imagestyle/imagestylecommand~ImageStyleCommand `'imageStyle'` command} that accepts a value based on the {@link module:image/image~ImageConfig#styles `image.styles`} configuration option (for example, `'full'` and `'side'`):
|
|
|
|
|
|
|
|
```js
|
|
```js
|
|
|
editor.execute( 'imageStyle', { value: 'side' } );
|
|
editor.execute( 'imageStyle', { value: 'side' } );
|
|
@@ -535,12 +579,12 @@ The {@link module:image/imagestyle~ImageStyle} plugin registers:
|
|
|
|
|
|
|
|
The {@link module:image/imageupload~ImageUpload} plugin registers:
|
|
The {@link module:image/imageupload~ImageUpload} plugin registers:
|
|
|
|
|
|
|
|
-* The `'imageUpload'` button which opens the native file browser to let you upload a file directly from your disk.
|
|
|
|
|
-* The {@link module:image/imageupload/imageuploadcommand~ImageUploadCommand `'imageUpload'` command} which accepts the file to upload.
|
|
|
|
|
|
|
+* The `'imageUpload'` button that opens the native file browser to let you upload a file directly from your disk.
|
|
|
|
|
+* The {@link module:image/imageupload/imageuploadcommand~ImageUploadCommand `'imageUpload'` command} that accepts the file to upload.
|
|
|
|
|
|
|
|
The {@link module:image/imageresize~ImageResize} plugin registers:
|
|
The {@link module:image/imageresize~ImageResize} plugin registers:
|
|
|
|
|
|
|
|
-* The {@link module:image/imageresize/imageresizecommand~ImageResizeCommand `'imageResize'` command} which accepts the target width.
|
|
|
|
|
|
|
+* The {@link module:image/imageresize/imageresizecommand~ImageResizeCommand `'imageResize'` command} that accepts the target width.
|
|
|
|
|
|
|
|
<info-box>
|
|
<info-box>
|
|
|
We recommend using the official {@link framework/guides/development-tools#ckeditor-5-inspector CKEditor 5 inspector} for development and debugging. It will give you tons of useful information about the state of the editor such as internal data structures, selection, commands, and many more.
|
|
We recommend using the official {@link framework/guides/development-tools#ckeditor-5-inspector CKEditor 5 inspector} for development and debugging. It will give you tons of useful information about the state of the editor such as internal data structures, selection, commands, and many more.
|