I'm using hook_node_presave() to set values for fields that were left empty when a node is created/updated. Text fields are easy enough ($node->field_name['und'][0]['value'] = 'Default text'), but image fields have got me stumped...

Image fields have lots of array values (e.g. fid, width, height, alt, etc.). I'm assuming there's a function I can call that'll create all the necessary values, but I can't seem to find it.

On top of all that, I have an external image URL that I'd like to programatically download and save to the image field. I'm using the Filefield Sources module to do this in the interface, but again, I need to know how to do this programatically instead.