It is quite possible that I'm just looking for help finding the name of a function that already exists within drupal (7) but sometimes the documentation is a bit difficult to navigate. Hopefully someone can help me.
I have a node that has a custom field.
I am working within a template field--mycustomcontenttype.tpl.php
and so am trying to find the name of the PHP function that outputs and image field with image styles.
mycustomcontenttype
is a NODE with the following additional field:
[field_image] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 51
[alt] => ImageAltText
[title] =>
[width] => 150
[height] => 150
[uid] => 29
[filename] => myimagename.jpg
[uri] => public://myimagename.jpg
[filemime] => image/jpeg
[filesize] => 8812
[status] => 1
[timestamp] => 1339445372
[uuid] => a088ea8f-ddf9-47d1-b013-19c8f8cada07
[metatags] => Array
(
)
)
So I could display the image using an (ugly) hand rolled functions that takes the value found in $item['#options']['entity']->field_image
and does the substitution of public://
for the actual server path, and then it's also possible that I'm going to want to load the image with the correct drupal image style (thumbnail, custom-style, etc...)
Sadly, I just have no idea what the name of the function that works something like: unknown_function_name_drupal_image_print($item['#options']['entity']->field_image, 'thumnail');
is.
Is there anyone who can help me find this?
You can use the folowing methods to get the uri or the url: $entity->get('field_image')->entity->getFileUri(); $entity->get('field_image')->entity->url();
Choose Administer > Structure > Content types > Manage display. Choose the display (e.g. "default" or "teaser") via the tab buttons. Click the gear wheel button to choose an image style; you are also able to link the image to the node. Save the settings.
Go to Structure -> “Content types”(admin/structure/types) and click on “manage display” within the Article row. 2. Select “Rendered file” from the Format drop-down list within the Image field and click on Save. That's all we need to change on the Image field, next we'll configure the Image file entity display.
On the File System page, the top field is named Public file system path. The content of this field contains the path where the images are uploaded into your Drupal 7 structure. The default location is sites/default/files.
You are looking for image_style_url(style_name, image_url);
For example:
<?='<img src="'.image_style_url('fullwidth', $node->field_page_image['und'][0]['filename']).'" />'?>
EDIT
As pointed out you can also set the image style in the Manage Display page for the content type and then output using render.
<?php print render($content['field_image']); ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With