Skip to content

Instantly share code, notes, and snippets.

@BBGuy
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BBGuy/592f191e2ab120f75df0 to your computer and use it in GitHub Desktop.
Save BBGuy/592f191e2ab120f75df0 to your computer and use it in GitHub Desktop.
Working with Images in Drupal
// Using the Entity API
$image = $MY_ENITIY->field_image->value();
$variables = array(
'style_name' => 'my_style__img',
'path' => $centre['image']['uri'],
'width' => $centre['image']['width'],
'height' => $centre['image']['height'],
);
$img = theme('image_style', $variables );
// This however will not work wor with defaul images, you can use field_get_default_value() if comes back empty
if (empty($image)) {
$image = field_get_default_value(..)
}
// You can also use add a view mode or the display settings to field_view_field()
// Load and render the filed (will work with default image) using a taxonomy term in the example
$entity = $MY_ENITIY->value();
$image = field_view_field('taxonomy_term', $entity, 'field_image');
$image = render($image);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment