Drupal - Proper way to get the base path when including an image from a module?

Drupal core uses file_create_url() for internal images like this (eg, the default favicon.ico handling in includes/theme.inc).

This ensures that hook_file_url_alter() gets called (the CDN module does this), that the basepath gets set, and that everything is escaped properly.

So, I would use

$path = drupal_get_path('module', 'mymodle');
$url = file_create_url($path . '/images/some.jpg');

You could use

theme_image

e.g:

  $variables = array(
    'path' => drupal_get_path('module', 'my_module').'/images/image.jpg', 
    'alt' => 'My image',
    'title' => 'My image title',
    'attributes' => array('class' => array('my-image')),
  );
  $img = theme('image', $variables);

Tags:

Uri

I18N L10N