1

I have an object which is created by transferring the image from another server. The image obj looks like this:

$ImgObj = stdClass Object ( [fid] => 595 
[uri] => public://assets/TLK/TLK-4300.jpg 
[filename] => TLK-4300.jpg 
[filemime] => image/jpeg 
[uid] => 1 
[status] => 1 
[timestamp] => 1459790167 
[filesize] => 24616 
[type] => image 
[metadata] => Array ( [width] => 220 [height] => 140 ) 
)

I am creating a node which has other fields in it and I'm trying to add this image object to it. I'm creating a wrapper for the node using:

$entity = entity_create('node', $values); //Values is an array defined earlier     
$ewrapper = entity_metadata_wrapper('node', $entity);

and want to add the image something like this:

$ewrapper->field_main_image->set($ImgObj);

I've tried a number of options and can't get it to work. I've googled it and tried various methods but always get an error message saying I'm using the wrong type or something like that. Any help much appreciated - thanks.

3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.