Hopp til hovedinnhold

Drupal 7 image styles

Skrevet av helge 12. Jan. 2016

If you need to get the url or print the image of a Drupal 7 image field with a specific image style you can do it like this:


<?php
$wrapper = entity_metadata_wrapper('node', $node);
$image_style = 'large';
$file = file_load($wrapper->field_image->file->fid->value());

// get the url
$url = image_style_url($image_style, $file->uri);

// or the html
$variables = array(
  'style_name' => $image_style,
  'path' => $file->uri,
  'height' => NULL,
  'width' => NULL,
  'alt' => $wrapper->field_image->alt->value(),
  'title' => $wrapper->field_image->title->value(),
);
$html = theme_image_style($variables); 

If you need to get the configured image-style for a node's view mode you could do something like this:


<?php
$view_mode = 'teaser';
$instance_info = field_info_instance('node', 'field_image', 'article');
// you should do some checks on the $instance_info array before using it like this
$image_style = $instance_info['display'][$view_mode]['settings']['style']; 

Prisforespørsel

Svar på noen enkle spørsmål om hva du ønsker
og vi gir deg et prisoverslag. Enkelt og greit.

Kontakt

Oneiros as

Besøk: Johan Berentsens vei 63, Laksevåg
Post: Gravdalsveien 176, 5165
Tel: 402 26 770
E-post: post@oneiros.no