Adding link with image in the .tpl.php file
I think what you want is something to link to that will execute your PHP "callback". Have a look at hook_menu() in the Drupal API. 

Here's an example:

/**
 * Implements hook_menu().
 */
function MODULENAME_menu() {
  $items = array();
  $items['mymodule/callback'] = array(
    'page callback' =&gt; 'MODULENAME_do_callback',
    'access arguments' =&gt; array('access content'), // You can specify a permission here.
    'type' =&gt; MENU_CALLBACK,
  );
  return $items;
}

function MODULENAME_do_callback() {
  // your php here
}


With that you should be able to link your image (just with standard HTML) to yourdomain.com/mymodule/callback and it will execute your code. 

Note: Be sure to clear all caches after adding your hook_menu() implementation.