Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

This question already has an answer here:

I have a piece of code that prepares renderable array for my images:

if( !empty($row['image_file_id'])) {
  $row['thumbnail'] = array(
    '#theme' => 'image_style',
    '#path' => _mymodule_uri_by_id((integer)$row['image_file_id']),
    '#style_name' => 'product_thumbnail_small',
    '#attributes' => array(
      'alt' => $row['image_alt'],
      'title' => $row['image_title'],
    ),
  );
}

It works OK:

Screenshot to show it works OK

But I want to add else with image provided within a module. I still want this image to go thorough all image style processing etc. I want my theming colleagues to be able to simply not care if they'll ever decide to add some effects or change resolution. But of course this image is in module directory, not in public://. And it means this will not work:

else {
  $row['thumbnail'] = array(
    '#theme' => 'image_style',
    '#path' => drupal_get_path('module', 'mymodule') . '/frontend/noimage.png',
    '#style_name' => 'product_thumbnail_small',
    '#attributes' => array(
      'alt' => 'some universal stub',
      'title' => 'some universal stub',
    ),
  );
}

It gives:

Screenshot to show how it fails

And browser tries to read that image from http://example.com/sites/default/files/styles/product_thumbnail_small/public//sites/default/modules/mymodule/frontend/noimage.png?itok=-yYlM4ns

This gives nothing (status reports says "access denied"), unless I manually place image in public://sites/default/modules/mymodule/frontend - but I don't want it to be in public file system, I want it to stay in module space. How can I make it work?

share|improve this question

marked as duplicate by Mołot, MPD Apr 6 at 13:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
I'm sure I had this working once, in another project. Probably something obvious I just fail to find proper Google query for. –  Mołot Mar 20 at 14:07
add comment

1 Answer 1

up vote 4 down vote accepted

Simply put...you can't, unfortunately (well not without changing some core stuff at least)

From the comments for theme_image_style()

This function does not work with images outside the files directory nor with remotely hosted images.

share|improve this answer
    
I almost can. Marked this question as a duplicate of the one that gave me a working solution. Too bad this can't work out of the box, good there is feasible workaround –  Mołot Mar 20 at 14:51
    
I thought this sounded familiar ;) Are you opposed to me merging this with the duplicate? –  Clive Mar 20 at 14:52
    
Would I vote to close as a duplicate myself? ;) Merge if you feel like, I think basically they are the same question, just needed to search for function, not render array. –  Mołot Mar 20 at 14:54
    
Cool, will sort it out later –  Clive Mar 20 at 14:55
add comment

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