How to override/enhance file_save_upload() function of file.inc? For a specific requirement, wherein whenever an image is uploaded to a particular field of a node, a watermark should be added to it, I made changes in file_save_upload() function of file.inc

if (!drupal_move_uploaded_file($_FILES['files']['tmp_name'][$source], $file-&gt;uri)) {
    form_set_error($source, t('File upload error. Could not move uploaded file.'));
    watchdog('file', 'Upload error. Could not move uploaded file %file to destination    %destination.', array('%file' =&gt; $file-&gt;filename, '%destination' =&gt; $file-&gt;uri));
   return FALSE;
}
else{
    process_image(drupal_realpath($file-&gt;uri));
}


But these changes will be lost whenever Drupal core will be upgraded. So what is the best way to override/enhance file_save_upload() function of file.inc or any function in the core drupal?
Drupal runs on a Never hack core policy. 

The Drupal way to add a watermark to image is to use hook_form_alter to modify the form submit and do your things with $form_state['values']['YOUR_FIELD']

Eg:

function mymodule_form_alter(&amp;$form, $form_state, $form_id)  {
  switch ($form_id)  {
   case 'YOURFORMID':
     $form['#submit'][] = 'yourModule_yourform_submit';
     break;
   }
 }

function yourModule_yourform_submit($form, &amp;$form_state) {
    // do what you want to do 
    // use $form_state['values']
}


Or Try ImageCache Actions module.


  Watermarking - a much requested addition that enables you to place any
  image anywhere over a source picture, with alpha transparency