ImageConfig
The configuration of the image features. Used by the image features in the @ckeditor/ckeditor5-image package.
ClassicEditor
.create( editorElement, {
image: ... // Image feature options.
} )
.then( ... )
.catch( ... );
See all editor options.
Properties
insert : ImageInsertConfig | undefinedmodule:image/imageconfig~ImageConfig#insertThe image insert configuration.
resizeOptions : Array<ImageResizeOption> | undefinedmodule:image/imageconfig~ImageConfig#resizeOptionsThe image resize options.
Each option should have at least these two properties:
- name: The name of the UI component registered in the global component factory of the editor, representing the button a user can click to change the size of an image,
- value: An actual image width applied when a user clicks the mentioned button (
ResizeImageCommandgets executed). The value property is combined with theconfig.image.resizeUnit(%by default). For instance:value: '50'andresizeUnit: '%'will render as'50%'in the UI.
Resetting the image size
If you want to set an option that will reset image to its original size, you need to pass a
nullvalue to one of the options. The:originaltoken is not mandatory, you can call it anything you wish, but it must reflect in the standalone buttons configuration for the image toolbar.ClassicEditor .create( editorElement, { image: { resizeUnit: "%", resizeOptions: [ { name: 'resizeImage:original', value: null }, { name: 'resizeImage:50', value: '50' }, { name: 'resizeImage:75', value: '75' } ] } } ) .then( ... ) .catch( ... );Copy codeResizing images using a dropdown
With resize options defined, you can decide whether you want to display them as a dropdown or as standalone buttons. For the dropdown, you need to pass only the
resizeImagetoken to theconfig.image.toolbar. The dropdown contains all defined options by default:ClassicEditor .create( editorElement, { image: { resizeUnit: "%", resizeOptions: [ { name: 'resizeImage:original', value: null }, { name: 'resizeImage:50', value: '50' }, { name: 'resizeImage:75', value: '75' } ], toolbar: [ 'resizeImage', ... ], } } ) .then( ... ) .catch( ... );Copy codeResizing images using individual buttons
If you want to have separate buttons for each option, pass their names to the
config.image.toolbarinstead. Please keep in mind that this time you must define the additionaliconproperty:ClassicEditor .create( editorElement, { image: { resizeUnit: "%", resizeOptions: [ { name: 'resizeImage:original', value: null, icon: 'original' }, { name: 'resizeImage:25', value: '25', icon: 'small' }, { name: 'resizeImage:50', value: '50', icon: 'medium' }, { name: 'resizeImage:75', value: '75', icon: 'large' } ], toolbar: [ 'resizeImage:25', 'resizeImage:50', 'resizeImage:75', 'resizeImage:original', ... ], } } ) .then( ... ) .catch( ... );Copy codeCustomizing resize button labels
You can set your own label for each resize button. To do that, add the
labelproperty like in the example below.- When using the dropdown, the labels are displayed on the list of all options when you open the dropdown.
- When using standalone buttons, the labels will are displayed as tooltips when a user hovers over the button.
ClassicEditor .create( editorElement, { image: { resizeUnit: "%", resizeOptions: [ { name: 'resizeImage:original', value: null, label: 'Original size' // Note: add the "icon" property if you're configuring a standalone button. }, { name: 'resizeImage:50', value: '50', label: 'Medium size' // Note: add the "icon" property if you're configuring a standalone button. }, { name: 'resizeImage:75', value: '75', label: 'Large size' // Note: add the "icon" property if you're configuring a standalone button. } ] } } ) .then( ... ) .catch( ... );Copy codeDefault value
The following configuration is used by default:
resizeOptions = [ { name: 'resizeImage:original', value: null, icon: 'original' }, { name: 'resizeImage:25', value: '25', icon: 'small' }, { name: 'resizeImage:50', value: '50', icon: 'medium' }, { name: 'resizeImage:75', value: '75', icon: 'large' } ];Copy coderesizeUnit : 'px' | '%' | undefinedmodule:image/imageconfig~ImageConfig#resizeUnitThe available options are
'px'or'%'.Determines the size unit applied to the resized image.
ClassicEditor .create( editorElement, { image: { resizeUnit: 'px' } } ) .then( ... ) .catch( ... );Copy codeThis option is used by the
ImageResizefeature.Defaults to
'%'styles : ImageStyleConfig | undefinedmodule:image/imageconfig~ImageConfig#stylesThe
ImageStyleplugin requires a list of the image style options to work properly. The default configuration is provided (listed below) and can be customized while creating the editor instance.Command
The
imageStyleCommandis configured based on the defined options, so you can change the style of the selected image by executing the following command:editor.execute( 'imageStyle' { value: 'alignLeft' } );Copy codeButtons
All of the image style options provided in the configuration are registered in the UI components factory with the "imageStyle:" prefixes and can be used in the image toolbar configuration. The buttons available by default depending on the loaded plugins are listed in the next section.
Read more about styling images in the Image styles guide.
Default options and buttons
If the custom configuration is not provided, the default configuration will be used depending on the loaded image editing plugins.
- If both
ImageBlockEditingandImageInlineEditingplugins are loaded (which is usually the default editor configuration), the following options will be available for the toolbar configuration. These options will be registered as the buttons with the "imageStyle:" prefixes.
const imageDefaultConfig = { styles: { options: [ 'inline', 'alignLeft', 'alignRight', 'alignCenter', 'alignBlockLeft', 'alignBlockRight', 'block', 'side' ] } };Copy code- If only the
ImageBlockEditingplugin is loaded, the following buttons (options) and groups will be available for the toolbar configuration. These options will be registered as the buttons with the "imageStyle:" prefixes.
const imageDefaultConfig = { styles: { options: [ 'block', 'side' ] } };Copy code- If only the
ImageInlineEditingplugin is loaded, the following buttons (options) and groups will available for the toolbar configuration. These options will be registered as the buttons with the "imageStyle:" prefixes.
const imageDefaultConfig = { styles: { options: [ 'inline', 'alignLeft', 'alignRight' ] } };Copy codeRead more about the default styling options.
Custom configuration
The image styles configuration can be customized in several ways:
- Any of the default styling options can be loaded by the reference to its name as follows:
ClassicEditor .create( editorElement, { image: { styles: { options: [ 'alignLeft', 'alignRight' ] } } } );Copy code- Each of the default image style options can be customized, e.g. to change the
icon,titleor CSSclassNameof the style. The feature also provides several default icons to choose from.
import customIcon from 'custom-icon.svg'; // ... ClassicEditor.create( editorElement, { image: styles: { options: { // This will only customize the icon of the "block" style. // Note: 'right' is one of default icons provided by the feature. { name: 'block', icon: 'right' }, // This will customize the icon, title and CSS class of the default "side" style. { name: 'side', icon: customIcon, title: 'My side style', className: 'custom-side-image' } } } } );Copy code- If none of the default image style options works for the integration, it is possible to define independent custom styles, too.
See the documentation about the image style options to define the custom image style configuration properly.
import redIcon from 'red-icon.svg'; import blueIcon from 'blue-icon.svg'; // ... ClassicEditor.create( editorElement, { image: styles: { // A list of completely custom styling options. options: [ { name: 'regular', modelElements: [ 'imageBlock', 'imageInline' ], title: 'Regular image', icon: 'full', isDefault: true }, { name: 'blue', modelElements: [ 'imageInline' ], title: 'Blue image', icon: blueIcon, className: 'image-blue' }, { name: 'red', modelElements: [ 'imageBlock' ], title: 'Red image', icon: redIcon, className: 'image-red' } ] } } );Copy code- If both
toolbar : Array<string | ImageStyleDropdownDefinition> | undefinedmodule:image/imageconfig~ImageConfig#toolbarItems to be placed in the image toolbar. This option is used by the
ImageToolbarfeature.Assuming that you use the following features:
ImageStyle(with a default configuration),ImageTextAlternative,ImageCaption,
the following toolbar items will be available in
ComponentFactory:'imageTextAlternative','toggleImageCaption',- buttons provided by the
ImageStyleplugin, - drop-downs provided by the
ImageStyleplugin,
so you can configure the toolbar like this:
const imageConfig = { toolbar: [ 'imageStyle:inline', 'imageStyle:wrapText', 'imageStyle:breakText', '|', 'toggleImageCaption', 'imageTextAlternative' ] };Copy codeBesides that, the
ImageStyleplugin allows to define a custom drop-down while configuring the toolbar.The same items can also be used in the main editor toolbar.
Read more about configuring toolbar in
toolbar.upload : ImageUploadConfig | undefinedmodule:image/imageconfig~ImageConfig#uploadThe image upload configuration.