[Drupal] How to create custom image style for media upload in CKEditor in Drupal 7

December 02, 2016 - 16:01

When I planned to use media upload in CKeditor for uploading files to the site, I faced one problem, i.e. I could use only predefined image style as preset to style my image. I wanted to use a custom preset to media upload. To achieve that we have to do some customization.

Add following custom code in our custom module.

 * Function to add custom preset.
function custom_entity_info_alter(&$entity_info) {
  // Support the media module, Here Medium and Full width - 1300*810 are custom preset.
  $entity_info['file']['view modes']['media_medium'] = array('label' => t('Medium'), 'custom settings' => TRUE);
  $entity_info['file']['view modes']['media_full_width'] = array('label' => t('Full width - 1300*810'), 'custom settings' => TRUE);  

Create new image styles and then edit the media file display: admin/config/media/file-types/manage/image/file-display to assign new image styles for custom presets.

Hope this helps! Please feel free to get in touch with us if any queries.

Get Drupal updates straight to your inbox

To prevent automated spam submissions leave this field empty.

Post your comments / questions