0

I have a module that doesn't seems to work correctly, so I dived into its code, and there is something that I don't understand:

The module does something like this: (I replaced the 'path' key with an hardcoded value to show the problem)

$params = array(
    'style_name' => $presetname,
    //'path' => $image_url,
    'path' => "public://images/image.jpg",
    'attributes' => $attributes,
    );

Then $param is sent to the theme_image_style() hook

$img = theme('image_style', $params);

The problem is that if i dump the output of theme_image_style():

dpm( $img);

then i get

<img typeof="foaf:Image" src="http://mysite.local/sites/default/files/styles//public/images/image.jpg?itok=qZxUAGIS" alt="" data-thmr="thmr_99 thmr_100" />

In admin/config/media/file-system, my public path is set as: sites/default/files

I should have:

src="http://mysite.local/sites/default/files/images/image.jpg

instead of:

src="http://mysite.local/sites/default/files/styles//public/images/image.jpg

Why does the theme function add 'styles//public' and where could I remove this?

Thanx in advance for your help

1
  • If you don't want a styled version of the image, don't use theme_image_style, - use theme_image instead
    – Clive
    Dec 6, 2013 at 15:29

1 Answer 1

2

Drupal 7 provide Image style functionality which allow administrator to set predefined size and can apply image style to any image in site.

Using image styles you can scale, crop, resize, rotate and desaturate images without affecting the original image. By default three sizes are defined: 'thumbnail,' 'medium', and 'large'. The thumbnail style, for example, is shown with the teaser for image posts and when browsing image galleries.

In your code, you have defined $img = theme('image_style', $params); which mean that you are applying image style to your image.

When we apply image style to any image, it will create a new image in styles/[stylename]/public directory and does not affect the original image source.

There is no stylename in your http://mysite.local/sites/default/files/styles//public/images/image.jpg url after style part of url, so I guess $presetname is not properly defined in your code.

You can try below exammple:

$params = array(
    'style_name' => 'thumbnail',
    //'path' => $image_url,
    'path' => "public://images/image.jpg",
    'attributes' => $attributes,
    );
$img = theme('image_style', $params);
1
  • Thanx jayendra, I added a style to my picture, and it works now! :)
    – matt
    Dec 6, 2013 at 16:00

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.