Serving an image programatically
You should be using hook_menu() to create a custom page from code. The hook_menu() allows to define a URL and page callback which will be called when user hit the url. Check the example below:

/**
  * Implements hook_menu().
  */
function [MODULE_NAME]_menu() {
  $items['MODULE_CALLBACK'] = array(
    'title' =&gt; 'My Custom URL',
    'page callback' =&gt; '_MODULE_NAME_page_callback',
    'access arguments' =&gt; array('access content'),
  );

  return $items;
}

function _MODULE_NAME_page_callback() {
  $image_name = (!empty($_GET['image']) ? $_GET['image'] : '');

  // Write code here.
  $data = $image_name;

  return $data;
}


The _MODULE_NAME_page_callback() callback will be called when user hit the URL as sitename.com/MODULE_CALLBACK?image=imagename.jpg.