Last active
August 29, 2015 14:20
-
-
Save BBGuy/592f191e2ab120f75df0 to your computer and use it in GitHub Desktop.
Working with Images in Drupal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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