Drupal - How to programmatically get list of available image styles

use

use Drupal\image\Entity\ImageStyle;

and load all image style with

$styles = ImageStyle::loadMultiple();

Also you can use entity_load_multiple with

 styles = \Drupal::entityTypeManager()->getStorage('image_style')->loadMultiple();

You can get a list of all image styles with an entity query:

$image_styles = \Drupal::entityQuery('image_style')
        ->execute();

If you query the config entity image_style, you get an array with a list of available image styles.

If you use loadMultiple() on the config entity, you get an array with the loaded config objects. Use this, if you need the configurations.

If you only need a list, use entity query, because this is faster.

Tags:

Media

8