Programmatically save image together with its ALT I am not sure what is the benefit of using system_retrieve_file mentioned on Save image from URL to a field from a custom module, so I just use the following simple code to save image programmatically:

    $file = file_save_data(file_get_contents($url), file_default_scheme().'://field/image/'.basename($url));
    $file-&gt;status = 1;
    $node-&gt;field_image['und'][0] = (array)$file;
    node_save($node);


Works fine, so now I am trying to figure out how to save the enabled alt value which is stored in $alt variable.

When I output what the $file array contains with dsm(print_r($file,true)); it shows only:

stdClass Object
(
[fid] =&gt; 9
[uri] =&gt; public://field/image/150304192032_monalisa_624x351_afp_0.jpg
[filename] =&gt; 150304192032_monalisa_624x351_afp.jpg
[filemime] =&gt; image/jpeg
[uid] =&gt; 1
[status] =&gt; 1
[timestamp] =&gt; 1425596902
[filesize] =&gt; 28642
)


Unfortunately, it doesn't contain neither title or alt. Could anyone help me to get this sorted out? Thanks!
As far as Drupal 8 is concerned, there is another solution :

//    $file : my File Entity
//    $node : my (Node) Entity having an Image File field associated
$node-&gt;field_my_image_field[] = [
 'target_id' =&gt; $file-&gt;id(),
 'alt' =&gt; 'Alt. text',
];
$node-&gt;save();


Well, I think that 'width', 'height' and 'title' are also available in the setting array (but target_id seems required).
cf: https://api.drupal.org/api/drupal/core%21modules%21image%21src%21Plugin%21Field%21FieldType%21ImageItem.php/class/ImageItem/8.2.x
(look at the source code, generateSampleValue() method).