Assign file to entity image field (Programmatically)
You add an image to the field by assigning the file id to target_id:

$entity-&gt;field_someimage[] = [
  'target_id' =&gt; $file-&gt;id(),
  'alt' =&gt; 'Alt text',
  'title' =&gt; 'Title',
];
$entity-save();


You can add other properties at the same time. An image usually needs a title and an alt text.