Interface

ImageConfig (image)

@ckeditor/ckeditor5-image/src/image

interface

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.

Filtering

Properties

  • resizeOptions : Array.<ImageResizeOption>

    The 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 (ImageResizeCommand gets executed). The value property is combined with the config.image.resizeUnit (% by default). For instance: value: '50' and resizeUnit: '%' 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 null value to one of the options. The :original token 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: 'imageResize:original',
    				value: null
    			},
    			{
    				name: 'imageResize:50',
    				value: '50'
    			},
    			{
    				name: 'imageResize:75',
    				value: '75'
    			} ]
    		}
    	} )
    	.then( ... )
    	.catch( ... );
    

    Resizing 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 imageResize token to the config.image.toolbar. The dropdown contains all defined options by default:

    ClassicEditor
    	.create( editorElement, {
    		image: {
    			resizeUnit: "%",
    			resizeOptions: [ {
    				name: 'imageResize:original',
    				value: null
    			},
    			{
    				name: 'imageResize:50',
    				value: '50'
    			},
    			{
    				name: 'imageResize:75',
    				value: '75'
    			} ],
    			toolbar: [ 'imageResize', ... ],
    		}
    	} )
    	.then( ... )
    	.catch( ... );
    

    Resizing images using individual buttons

    If you want to have separate buttons for each option, pass their names to the config.image.toolbar instead. Please keep in mind that this time you must define the additional icon property:

    ClassicEditor
    	.create( editorElement, {
    		image: {
    			resizeUnit: "%",
    			resizeOptions: [ {
    				name: 'imageResize:original',
    				value: null,
    				icon: 'original'
    			},
    			{
    				name: 'imageResize:25',
    				value: '25',
    				icon: 'small'
    			},
    			{
    				name: 'imageResize:50',
    				value: '50',
    				icon: 'medium'
    			},
    			{
    				name: 'imageResize:75',
    				value: '75',
    				icon: 'large'
    			} ],
    			toolbar: [ 'imageResize:25', 'imageResize:50', 'imageResize:75', 'imageResize:original', ... ],
    		}
    	} )
    	.then( ... )
    	.catch( ... );
    

    Customizing resize button labels

    You can set your own label for each resize button. To do that, add the label property 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: 'imageResize:original',
      				value: null,
      				label: 'Original size'
      				// Note: add the "icon" property if you're configuring a standalone button.
      			},
      			{
      				name: 'imageResize:50',
      				value: '50',
      				label: 'Medium size'
      				// Note: add the "icon" property if you're configuring a standalone button.
      			},
      			{
      				name: 'imageResize:75',
      				value: '75',
      				label: 'Large size'
      				// Note: add the "icon" property if you're configuring a standalone button.
      			} ]
      		}
      	} )
      	.then( ... )
      	.catch( ... );
      

    Default value

    The following configuration is used by default:

    resizeOptions = [
    	{
    		name: 'imageResize:original',
    		value: null,
    		icon: 'original'
    	},
    	{
    		name: 'imageResize:25',
    		value: '25',
    		icon: 'small'
    	},
    	{
    		name: 'imageResize:50',
    		value: '50',
    		icon: 'medium'
    	},
    	{
    		name: 'imageResize:75',
    		value: '75',
    		icon: 'large'
    	}
    ];
  • resizeUnit : String

    The available options are 'px' or '%'.

    Determines the size unit applied to the resized image.

    ClassicEditor
    	.create( editorElement, {
    		image: {
    			resizeUnit: 'px'
    		}
    	} )
    	.then( ... )
    	.catch( ... );
    

    This option is used by the ImageResize feature.

    Defaults to '%'

  • styles : Array.<ImageStyleFormat>

    Available image styles.

    The default value is:

    const imageConfig = {
    	styles: [ 'full', 'side' ]
    };
    

    which configures two default styles:

    • the "full" style which does not apply any class, e.g. for images styled to span 100% width of the content,
    • the "side" style with the .image-style-side CSS class.

    See defaultStyles to learn more about default styles provided by the image feature.

    The default styles can be customized, e.g. to change the icon, title or CSS class of the style. The feature also provides several default icons to choose from.

    import customIcon from 'custom-icon.svg';
    
    // ...
    
    const imageConfig = {
    	styles: [
    		// This will only customize the icon of the "full" style.
    		// Note: 'right' is one of default icons provided by the feature.
    		{ name: 'full', 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' }
    	]
    };
    

    If none of the default styles is good enough, it is possible to define independent custom styles, too:

    import fullSizeIcon from '@ckeditor/ckeditor5-core/theme/icons/object-center.svg';
    import sideIcon from '@ckeditor/ckeditor5-core/theme/icons/object-right.svg';
    
    // ...
    
    const imageConfig = {
    	styles: [
    		// A completely custom full size style with no class, used as a default.
    		{ name: 'fullSize', title: 'Full size', icon: fullSizeIcon, isDefault: true },
    
    		{ name: 'side', title: 'To the side', icon: sideIcon, className: 'side-image' }
    	]
    };
    

    Note: Setting title to one of localizedDefaultStylesTitles will automatically translate it to the language of the editor.

    Read more about styling images in the Image styles guide.

    The feature creates commands based on defined styles, so you can change the style of a selected image by executing the following command:

    editor.execute( 'imageStyle' { value: 'side' } );
    

    The feature also creates buttons that execute the commands. So, assuming that you use the default image styles setting, you can configure the image toolbar (or any other toolbar) to contain these options:

    const imageConfig = {
    	toolbar: [ 'imageStyle:full', 'imageStyle:side' ]
    };
  • toolbar : Array.<String>

    Items to be placed in the image toolbar. This option is used by the ImageToolbar feature.

    Assuming that you use the following features:

    three toolbar items will be available in ComponentFactory: 'imageStyle:full', 'imageStyle:side', and 'imageTextAlternative' so you can configure the toolbar like this:

    const imageConfig = {
    	toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ]
    };
    

    Of course, the same buttons can also be used in the main editor toolbar.

    Read more about configuring toolbar in toolbar.

  • upload : ImageUploadConfig

    The image upload configuration.

  • insert : ImageInsertConfig

    protected

    The image insert configuration.