In D7, is there a way to get an image style assigned to an image field? if I have created an image style, say, my_image_style by overriding a default image style (thumbnail, medium or large at /admin/config/media/image-styles) and then assigned it to a field_image of a node at /admin/structure/types/manage/article/display, how can I programmatically determine what style does field_image have?
1 Answer
You can use the field_info_instance()
function to get that information:
$entity_type = 'node';
$field_name = 'field_image';
$bundle = 'article'; // Or whatever content type you need.
$view_mode = 'default'; // Or whatever view mode you want to get settings for, e.g. teaser.
$info = field_info_instance($entity_type, $field_name, $bundle);
$settings = $info['display'][$view_mode]['settings'];
$image_style = $settings['image_style'];