[Drupal] How to Create Custom Image style for Media Upload in CKEditor in Drupal 7

| | 1 min read

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 a 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 the 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.