Is it possible to add an image to a node programmatically?
This works for me:
define('DRUPAL_ROOT', $_SERVER['DOCUMENT_ROOT']);
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$node = node_load(99);
$filename = 'image.txt';
chdir(DRUPAL_ROOT);
$image = file_get_contents('http://www.ibiblio.org/wm/paint/auth/gogh/gogh.white-house.jpg');
$file = file_save_data($image, 'public://' . $filename, FILE_EXISTS_RENAME);
$node->field_imagen_producto = array(LANGUAGE_NONE => array('0' => (array)$file));
node_save($node);
Yes, make it part of the $node object when you save it. Save it using node_save().