Is it possible to return an image in a computed field?
I would like to use it to scale an image but I got the error
Recoverable fatal error: Object of class stdClass could not be converted to string in DatabaseStatementBase->execute() (line 2136 of /home/xxx/includes/database/

My computed field code is:
$file = file_load($entity->uc_product_image['und'][0]['fid']);
$image = image_load($file->uri);
//$scaled = image_scale($image, 200);
$entity_field[0]['value'] = $image;


EmmyS’s picture

Assuming that $file->uri is actually returning something valid, try this:

$uri = $file->uri;

$icon_vars = array(
   'path' => file_create_url($uri),
$my_img = theme_image($icon_vars);
$entity_field[0]['value'] = $my_img;
GBurg’s picture

This post helped me to create a default image for a passport photo (pasfoto), if no photo is set. The image is dependable on your gender (geslacht), male (man) or female (vrouw). So it first checks if the pasfoto is already set (it is an image field cropped). If not, it builds a default value.

// try to get the
$pasfoto = "";
$fielditems = field_get_items($entity_type, $entity, 'field_pasfoto');

if ($fielditems  !== false && !empty($fielditems)) {
  // get file
  $fid = $fielditems[0]['fid'];
  $file = file_load($fid);
  // create image
  $imgvars = array(
    'path' => $file->uri,
    'getsize' => FALSE,
    'attributes' => array('class' => 'preview-existing'),
  $my_img = theme_image($imgvars);
} else {
  // get geslacht
  $geslacht_item = field_get_items($entity_type, $entity, 'field_geslacht');
  $geslacht_term = taxonomy_term_load($geslacht_item['0']['tid']);
  $geslacht = strtolower($geslacht_term->name);
  // get image path
  if ($geslacht == "man") $pasfoto = drupal_get_path('theme', 'golfers')."/images/defaults/pasfoto_anon_man.jpg";
  else $pasfoto = drupal_get_path('theme', 'golfers')."/images/defaults/pasfoto_anon_vrouw.jpg";

  // create image
  $icon_vars = array(
   'path' => file_create_url($pasfoto),
  $my_img = theme_image($icon_vars);

$entity_field[0]['value'] = $my_img;