I'm struggling with a piece of code in my views field template.

A short overview of the situation:

  • Node product has a field with filename for an image
  • Images are added with filezilla in default/files/products

What is the best way to implement image styles on these images. My code:

 print theme('image_style', array('style_name' => 'product_overzicht', 'path' => $img_url)); 

Where $img_url is just a simple variable, like: img_filename.jpg

This doesn't work because the folder of that image style is empty. I know the easy way is to use an image field on my product node but this can't be done here. I use a excel import for all products and the image filename is a column in that excel file. Images are all together in a folder.

Does anybody know a way do this or a good workaround. CSS markup is not good because the image size needs to be as low as possible in the view but on de node details page I would like to show the entire image.

Any tips or advice is welcome!

  • My first thought would be that your $img_url is incomplete. You say the images are uploaded to sites/default/files/products so $img_url should be 'products/filename.jpg' i.e. the path relative to sites/default/files. If the variables supplied to the theme function are correct, Drupal should automatically generate the folder contents during the page request.
    – morbiD
    Commented Dec 9, 2015 at 12:19
  • You are correct. I did not apply the URI correct. Thank you for your reaction!
    – Simon H
    Commented Dec 9, 2015 at 13:26

1 Answer 1


Try something like this :

<img src="<?php print image_style_url('product_overzicht', $img_url);?>">

Where $img_url should be uri, which in your case can be : public://products/img_filename.jpg

  • Thank you for your reply, I tried this but the problem stays. I don't really understand why this would make a difference? Can you explain this a little perhaps, I'm a beginner/junoir in Drupal. Each time I use the image_style_url() function, Drupal looks in the sites/default/product_overzicht folder. But the images are in an other folder.
    – Simon H
    Commented Dec 9, 2015 at 12:06
  • Have you checked permissions to folder? When this code executes image_style_url suppose to generate image of style mentioned and return a url for it. Commented Dec 9, 2015 at 12:16
  • Check this : drupal.stackexchange.com/questions/91653/…, This can be a reason. Commented Dec 9, 2015 at 12:23
  • The permissions are 755 for the product_overzicht folder and 777 for the product_overzicht/public folder. When I compare this to an other image style folder, it looks the same. So I believe this is oke. I"m working on Drupal 7.40 currently. Where do you think I should put my files, now: sites/default/files/producten ? Thank you for the link, but find it quite difficult understanding.
    – Simon H
    Commented Dec 9, 2015 at 13:19
  • I must apologise, It was indeed the URI. I thank you a lot sir!
    – Simon H
    Commented Dec 9, 2015 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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