How can I register a image_style theme function in my module which only works in my theme's template? Is there a way to tell drupal that my module has a theme function which usually only works in my theme?

If I write in my theme's template.php:

function mytheme_image_style($variables) {

  // Determine the dimensions of the styled image.
  $dimensions = array(
    'width' =&gt; $variables['width'],
    'height' =&gt; $variables['height'],
  );

  image_style_transform_dimensions($variables['style_name'], $dimensions);

  $variables['width'] = $dimensions['width'];
  $variables['height'] = $dimensions['height'];

  // Determine the URL for the styled image.

  $variables['path'] = image_style_url($variables['style_name'], $variables['path']);

  // do additional stuff


  return theme('image', $variables);
}


everything works fine. If I move this code to a module it does not work, though:

function mymodule_image_style($variables) {

  // code


  return theme('image', $variables);
}


How can I use the theme_image_style function/hook in my module?
You need to use hook_theme_registry_alter() to replace the callback function for the image_style theme. Something like this should do it:

function MYMODULE_theme_registry_alter(&amp;$registry) {
  $registry['image_style']['function'] = 'mymodule_image_style';
}