3 added 726 characters in body; edited title
source | link

Render image from $node - no image style applied

I read tons of solutions how to render an image in a PHPtemplate where I have the whole node in $content, however I don't get how to render it using a $node object, including the given image style etc.

So I got all the code working and can access the node title for example via:

$node->title

How do I generate the proper HTML for this node (in this example the machine tag is field_slideshow_image)?

This line does not work, it gives me a 404 for the image URL:

<img src="<?php print image_style_url('slideshow', $node->field_slideshow_image['und'][0]['uri']); ?>" /> 

however, it contains at least the name of the actual image…

Update:

I found out that I have to force an image creation if there was none before, so now it works using:

$image_uri      = $node->field_slideshow_image['und'][0]['uri']; // or any public://my_image
$style = 'slideshow';
$derivative_uri = image_style_path($style, $image_uri);
$success        = file_exists($derivative_uri) || image_style_create_derivative($style, $image_uri, $derivative_uri);

$new_image_url  = file_create_url($derivative_uri);
echo $new_image_url."<br /><br />";
echo "<img class=\"slideshow_image\" src=\"".$new_image_url."\" />";

However, the image style "slideshow" does not get applied! I tried it with the default "thumbnail" and that one works well.

Render image from $node

I read tons of solutions how to render an image in a PHPtemplate where I have the whole node in $content, however I don't get how to render it using a $node object, including the given image style etc.

So I got all the code working and can access the node title for example via:

$node->title

How do I generate the proper HTML for this node (in this example the machine tag is field_slideshow_image)?

This line does not work, it gives me a 404 for the image URL:

<img src="<?php print image_style_url('slideshow', $node->field_slideshow_image['und'][0]['uri']); ?>" /> 

however, it contains at least the name of the actual image…

Render image from $node - no image style applied

I read tons of solutions how to render an image in a PHPtemplate where I have the whole node in $content, however I don't get how to render it using a $node object, including the given image style etc.

So I got all the code working and can access the node title for example via:

$node->title

How do I generate the proper HTML for this node (in this example the machine tag is field_slideshow_image)?

This line does not work, it gives me a 404 for the image URL:

<img src="<?php print image_style_url('slideshow', $node->field_slideshow_image['und'][0]['uri']); ?>" /> 

however, it contains at least the name of the actual image…

Update:

I found out that I have to force an image creation if there was none before, so now it works using:

$image_uri      = $node->field_slideshow_image['und'][0]['uri']; // or any public://my_image
$style = 'slideshow';
$derivative_uri = image_style_path($style, $image_uri);
$success        = file_exists($derivative_uri) || image_style_create_derivative($style, $image_uri, $derivative_uri);

$new_image_url  = file_create_url($derivative_uri);
echo $new_image_url."<br /><br />";
echo "<img class=\"slideshow_image\" src=\"".$new_image_url."\" />";

However, the image style "slideshow" does not get applied! I tried it with the default "thumbnail" and that one works well.

2 added 4 characters in body
source | link

I read tons of solutions how to render an image in a PHPtemplate where I have the whole node in $content, however I don't get how to render it using a $node object, including the given image style etc.

So I got all the code working and can access the node title for example via:

$node->title

How do I generate the proper HTML for this node (in this example the machine tag is field_slideshow_image)?

This line does not work, it gives me a 404 for the image URL:

<img src="<?php print image_style_url('image''slideshow', $node->field_slideshow_image['und'][0]['uri']); ?>" /> 

however, it contains at least the name of the actual image…

I read tons of solutions how to render an image in a PHPtemplate where I have the whole node in $content, however I don't get how to render it using a $node object, including the given image style etc.

So I got all the code working and can access the node title for example via:

$node->title

How do I generate the proper HTML for this node (in this example the machine tag is field_slideshow_image)?

This line does not work, it gives me a 404 for the image URL:

<img src="<?php print image_style_url('image', $node->field_slideshow_image['und'][0]['uri']); ?>" /> 

however, it contains at least the name of the actual image…

I read tons of solutions how to render an image in a PHPtemplate where I have the whole node in $content, however I don't get how to render it using a $node object, including the given image style etc.

So I got all the code working and can access the node title for example via:

$node->title

How do I generate the proper HTML for this node (in this example the machine tag is field_slideshow_image)?

This line does not work, it gives me a 404 for the image URL:

<img src="<?php print image_style_url('slideshow', $node->field_slideshow_image['und'][0]['uri']); ?>" /> 

however, it contains at least the name of the actual image…

1
source | link

Render image from $node

I read tons of solutions how to render an image in a PHPtemplate where I have the whole node in $content, however I don't get how to render it using a $node object, including the given image style etc.

So I got all the code working and can access the node title for example via:

$node->title

How do I generate the proper HTML for this node (in this example the machine tag is field_slideshow_image)?

This line does not work, it gives me a 404 for the image URL:

<img src="<?php print image_style_url('image', $node->field_slideshow_image['und'][0]['uri']); ?>" /> 

however, it contains at least the name of the actual image…