2

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 1

4

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'];
1
  • Where could I use this code?
    – SaidbakR
    Commented Sep 6, 2015 at 2:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.