0

I am writing a custom module that will output an image on the page. I believe that I should have this image in my module folder and not rely on that image being in the site files. I'm not sure how to reference that image to produce the img tag. mymodule -/mymodule.info -/mymodule.module -/files -/files/myimage.png

I want to be able to render the image so that the source is displayed with an img tag:

1
  • Please be sure that files have correct permission so that it can be displayed. – Sumit Madan Jun 16 '15 at 4:33
2

For outputing image, you should use theme function, with image theming. And path argument inside.

For example:

$img = theme('image', array('path' => "path to image"));
// $img will containt the image tag.
// path can be relative from drupal root, or it can be 'files' path (public://image.jpg)

Read more about it, you can here: https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_image/7

The power of Drupal in overwriting, so I suggest you to use theme way.

0

you can get the path for the current module with:

<?php
  drupal_get_path('module', 'my_module');
?>

so you can output with something like:

<img src="<?php print drupal_get_path('module', 'my_module') . '/images/image.jpg' ?>">

you obviously want to adjust the path and name (this example having a sub folder 'images' within the module folder), but that gives you an idea

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.