Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By ruudmaan on
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
If you have an image style
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.
Thanks! The only thing is,
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?
The "itok" part is for
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
Ok thanks, I was thinking
Ok thanks, I was thinking Google might now show the image in the results with the token behind it...
Hi,
Hi,
You can use below code.
Pragna J Bhalsod