How to change an image field to a certain fid programatically? Specifically, every time a comment is saved, I'd like to programatically change a comment field 'Picture' to an image field from the user who wrote the comment. I have the following custom module:

function MYMODULE_comment_presave($comment) {
    $user = user_load($comment-&gt;uid);
    $uid = $user-&gt;uid;

    $comment-&gt;field_picture['und'][0]['fid'] = $user-&gt;field_picture['und'][0]['fid'];
}


This doesn't work correctly, because the field_picture_alt, field_picture_width, field_picture_title and field_picture_height columns in my database don't get a value (they're NULL).

I've also tried

function MYMODULE_comment_presave($comment) {
    $user = user_load($comment-&gt;uid);
    $uid = $user-&gt;uid;

    $comment-&gt;field_picture['und'][0]['fid'] = $user-&gt;field_picture['und'][0]['fid'];
    $comment-&gt;field_picture['und'][0]['width'] = $user-&gt;field_picture['und'][0]['width'];
    $comment-&gt;field_picture['und'][0]['height'] = $user-&gt;field_picture['und'][0]['height'];
    $comment-&gt;field_picture['und'][0]['alt'] = $user-&gt;field_picture['und'][0]['alt'];
    $comment-&gt;field_picture['und'][0]['title'] = $user-&gt;field_picture['und'][0]['title'];
}


and that works perfectly.

However, I was wondering whether I always have to set the 'alt', 'title', 'width' and 'height' values manually as above.

Is there another faster way to inherit these caracteristics from the referred image? Can I for example inherit the 'height' and 'width' from an image style?
You can do this in the comment tpl file. Add something like this:

$img_array = array(
    'style_name' =&gt; 'thumbnail',
    'path' =&gt; $user-&gt;field_picture['und'][0]['uri'],
    'width' =&gt; '',
    'height' =&gt; '',
    'alt' =&gt; $user-&gt;field_picture['und'][0]['alt'],
    'title' =&gt; $user-&gt;field_picture['und'][0]['title'],
  );

$img = theme('image_style', $img_array);


You can then add &lt;?php print $img; ?&gt; where you want the image to appear.