I would be grateful if someone could tell me how to do this:

I'm currently trying:

<center><img src="<?php print $node->field_member_picture['view']; ?>" /></center><br/>

and

<center><img src="<?php print $node->field_member_picture['view']->filepath; ?>" /></center><br/>

but neither of these display the image. I'm sure the answer is straightforward but I really need some help on this because the imagefield becomes useless for me (on this particular site) otherwise.

Regards

Patrick

Comments

David Lesieur’s picture

Try this (untested):

<?php print theme('imagefield_image', $node->field_member_picture[0], "my alt text", "my title"); ?>

This should generate the required <img> tag.

BTW, I would not recommend using <center>, as it is not supported in XHTML strict.

Patrick Nelson’s picture

David,

Superb! Thanks for that - only one question left... how do I control the size of the image that is displayed? I want to allow people to upload in any size, but for the display in this instance I want to control the width...

Regards

Patrick

David Lesieur’s picture

Having imagefield resize images is still being discussed. But if it is acceptable on your site, you could set the display size in the img's attributes.

For example (again, untested!):

<?php print theme('imagefield_image', $node->field_member_picture[0], "my alt text", "my title", array('width' => 150, 'height' => 150)); ?>

With more PHP magic, you could preserve the image's aspect ratio. You will need getimagesize().

And in the following example aspect ratio is preserved, but you do not really control the size:

<?php print theme('imagefield_image', $node->field_member_picture[0], "my alt text", "my title", array('width' => '50%', 'height' => '50%')); ?>
Patrick Nelson’s picture

Thanks David, but that's not working. The image attributes seem to be already been fed in from somewhere. When I look at the source code on the page, this is what I see:

<img src="http://www.vcommunity.org.uk/files/logo.JPG" alt="" title="" width="850" height="219" width="50%" height="50%" />

The 50%'s are mine, but, as you can see, they're been superceded by the width and height figures before them. Any idea how I could get rid of them?

Regards

Patrick

Patrick Nelson’s picture

I found the answer. The line I've used that works is:

<?php
print theme('imagefield_image', $node->field_member_picture[0], "", "", array('width' => '200'), $getsize = FALSE);
?>

Many thanks for all your help, David.

karens’s picture

Status: Active » Fixed

Marking fixed. See http://drupal.org/project/imagefield project for more info and current version.

Anonymous’s picture

Status: Fixed » Closed (fixed)