Hello,

In my node.tpl I'm printing an image like this:
<img src="<?php print file_create_url($node->field_image[LANGUAGE_NONE][0]['uri']); ?>" />

But what I want is to also print the URL to the thumbnail (which I can use for my microdata thumbnail). How do I do that? In a way that I can do this:

<meta itemprop="thumbnailUrl" content="http://my/thumbnail/url.jpg" />

Been looking for hours, thanks so much!

Comments

pobster’s picture

If you have an image style called "thumbnail" then you can use this;

<meta itemprop="thumbnailUrl" content="<?php print image_style_url('thumbnail', $node->field_image[LANGUAGE_NONE][0]['uri']); ?>" />

It's not the best way TBH as it ignores internationalization, but seeing as that's a specific problem that you haven't addressed in your original question then it'll be fine to just use LANGUAGE_NONE.

ruudmaan’s picture

Thanks! The only thing is, this produces a link to: /sites/default/files/styles/thumbnail/public/img/witlof-rode-biet.jpg?itok=rGahjZxG

While I acually want it to just link to:

/sites/default/files/styles/thumbnail/public/img/witlof-rode-biet.jpg

Any idea how to achieve that?

pobster’s picture

The "itok" part is for security, generating images puts a load on your server - this prevents someone from unauthorized generation which is an easy DDOS attack. You should leave it really, it doesn't get in the way of anything? http://www.drupalcontrib.org/api/drupal/drupal%21modules%21image%21image...

You can possibly add this to your settings.php to remove them (if you really want to): $conf['image_allow_insecure_derivatives'] = TRUE;

See this: https://www.drupal.org/drupal-7.20-release-notes

ruudmaan’s picture

Ok thanks, I was thinking Google might now show the image in the results with the token behind it...

pragna’s picture

Hi,

You can use below code.

$imgpath = image_style_url('YOUR_STYLE', $YOUR_FIELD[0]['uri']);
$element = array(
  '#tag' => 'meta', 
  '#attributes' => array(
    'property' => 'og:image',
    'content' => $imgpath,
  ),
);
drupal_add_html_head($element, 'og_image');

Pragna J Bhalsod