Using an image field with entity metadata wrapper is a little bit more tricky than the usual text fields.
Anyway, it is pretty simple.
The main difference is to upload the image prior to adding it to the field.
Get raw version
- // First we have to upload the image to the public directory.
- $file_path = file_save_data(file_get_contents('/my_local_path/img1.jpg'), 'public://remote_name.jpg');
- // The wrapper can be created from a existing node or a new one. Once the wrapper is created, the usage is the same.
- // For example, for updating the existing node 55.
- $wrapper = entity_metadata_wrapper('node', 55);
- // We are updating an image field called field_banner_button_image.
- // And save the node