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.
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/database.inc).
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);
image_save($image);
$entity_field[0]['value'] = $image;
Comments
Comment #1
EmmyS CreditAttribution: EmmyS commentedAssuming that $file->uri is actually returning something valid, try this:
Comment #2
GBurg CreditAttribution: GBurg commentedThis 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.