There's a notice for height too, of course.

It appears theme_file_styles_image() needs to be changed, since core's API for theme_image_style() somehow (slightly) changed -- it's assuming 'width' and 'height' are always given to it. I'm not sure if theme_file_styles_image() could just pass in 0 for these, or really if core should be patched....

Here's the full backtrace:

Notice: Undefined index: width in theme_image_style() (line 1187 of modules/image/image.module).
theme_image_style(Array)
theme('image_style', Array)
theme_file_styles_image(Array)
theme('file_styles_image', Array)
FileStyles->thumbnail(Array)
StylesDefault->render(1)
FileStyles->render(1)
StylesDefault->display(1)
template_preprocess_styles(Array, 'styles')
theme('styles', Array)
theme_styles_field_formatter(Array)
theme('styles_field_formatter', Array)
styles_field_formatter_view('file', Object, NULL, NULL, 'en', Array, Array)
file_entity_file_formatter_file_field_view(Object, Array, 'en')
file_view_file(Object, 'file_styles_slideshow_default', 'en')
file_build_content(Object, 'file_styles_slideshow_default', 'en')
file_view(Object, 'file_styles_slideshow_default', NULL)
file_view_multiple(Array, 'file_styles_slideshow_default')
file_entity_field_formatter_view('field_collection_item', Object, Array, Array, 'und', Array, Array)
field_default_view('field_collection_item', Object, Array, Array, 'und', Array, Array, NULL)
_field_invoke('view', 'field_collection_item', Object, Array, NULL, Array)
_field_invoke_default('view', 'field_collection_item', Object, Array, NULL, Array)
field_view_field('field_collection_item', Object, 'field_slide_image', Array, 'und')
views_handler_field_field->set_items(Object, 0)
views_handler_field_field->post_execute(Array)
view->_post_execute()
view->execute(NULL)
view->render()
views_plugin_display->preview()
view->preview('default', Array)
slideshow_bean->view(Object, Array, 'default', NULL, NULL)
Bean->view('default')
bean_block_view('home-slideshow')
call_user_func_array('bean_block_view', Array)
module_invoke('bean', 'block_view', 'home-slideshow')
_block_render_blocks(Array)
context_reaction_block->block_list('page_top')
context_reaction_block->block_get_blocks_by_region('page_top')
context_reaction_block->execute(Array)
context_page_build(Array)
drupal_render_page(Array)
drupal_deliver_html_page(Array)
drupal_deliver_page(Array, '')
menu_execute_active_handler()

Comments

adamdicarlo’s picture

I wrote a small core patch to solve the problem after realizing width and height ARE supposed to be optional:

http://drupal.org/node/1129642#comment-5171160

So hopefully it will be accepted into core (or some version of it will) and that would render this issue obsolete.

stanhebben’s picture

I had this problem too; then I remembered I forget to run the update script.

Running the update script made the notices disappear.

chrissearle’s picture

Same issue here and the update did not help. The only way I could get rid of these was with the patch linked.

This will be theme dependent if I understand it (a theme that sends in the params won't throw the error).

So if I understand this right the question is are the params optional (in which case the patch is needed) or not (in which case the themes must all be updated).

afeijo’s picture

I'm running it in an dev server, without cache, the error shows up to every theme_image_style() I use

I did try to clear cache anyway, with drush cc all, no help

It only vanished when I apply the linked core patch, thanks adamdicarlo

I found lots of online sites with that error BTW :)

selfuntitled’s picture

Yep, I'm seeing this whenever the function is called. I just applied the core patch, and solved the problem.

brunorios1’s picture

i cleared the cache and solved the problem.

mattyohe’s picture

Clearing cache kills this issue.

adamdicarlo’s picture

Status: Active » Closed (works as designed)

OK, this seems to actually be a non-issue... closing it.

finn lewis’s picture

Just for the record, before upgrading to Drupal 7.9 I was using code like this:

$image = theme_image_style(
        array(
            'style_name' => 'custom_thumb',
            'path' => $path,
            'alt' => $alt,
            'attributes' => array('class' => 'image'),
        )
    );

which worked fine.

Since upgrading core to 7.9, I get the errors mentioned "Undefined index: width in ... theme_image_style()"

Now it appears I need to add width and height to each call to theme_image_style() like this:

$image = theme_image_style(
        array(
            'style_name' => 'hubpage_thumb',
            'path' => $path,
            'alt' => $alt,
            'attributes' => array('class' => 'image'),
            'width' => NULL,
            'height' => NULL, 
        )
    );

even if I don't have the dimensions to easily available.

I may have missed something in http://drupal.org/node/1129642, but passing a value (even if it is a NULL value) for width and height suppresses the notice for me.

artfulrobot’s picture

Status: Closed (works as designed) » Needs work

I agree with @ecofinn - doing this is a functioning workaround.

But confused @adamdicarlo - you say width and height are supposed to be optional but then you've submitted a patch and marked this as 'closed (works as designed)'. Surely if it's supposed to be optional, and throws notices if they're not provided, this can't be working as designed?

I've marked it 'needs work' (hope this is not bad etiquette) because as far as I can see it'll only be sorted when @adamdicarlo's patch or similar is committed.

adamdicarlo’s picture

@artfulrobot, I was misunderstanding how the theme system works. Since width and height are declared in hook_theme() for image_style, they will be automatically set to NULL if not provided by the code calling theme('image_style', array(...)).

That's why clearing the cache (should) fix the issue -- the theme registry needs to be rebuilt (since image_style's hook_theme() data changed for Drupal 7.9)....

jbrown’s picture

Status: Needs work » Closed (works as designed)
umanda’s picture

I also got this issue. What I did, I run the Update.php. It was fixed .

for run update.php

go this way http://www.yoursite.com/update.php

try this

Cheers

jbrown’s picture

@ecofinn it is not allowed to call theme functions directly - you must use theme().

finn lewis’s picture

@jbrown - thanks, I realised that shortly after posting the above. Thanks for the reminder!
For the record, in case anyone else ends up with the same issue, as jbrown mentions, we should always use the theme() function like this:

$image = theme('image_style',
        array(
            'style_name' => 'custom_thumb',
            'path' => $path,
            'alt' => $alt,
            'attributes' => array('class' => 'image'),
        )
    );

rather than calling the theme_image_style function directly, like this:

$image = theme_image_style(
        array(
            'style_name' => 'custom_thumb',
            'path' => $path,
            'alt' => $alt,
            'attributes' => array('class' => 'image'),
        )
    );
batigol’s picture

So...

<?php $user = user_load($user->uid);
		if ($user->picture) {
			print theme_image_style(
				array(
				'style_name' => 'user-menu-avatar',
				'path' => $user->picture->uri,
				'attributes' => array(
					'class' => 'user-menu-avatar'
					)
				)
			);
		};
	?>

I should change it to:

<?php $user = user_load($user->uid);
		if ($user->picture) {
			print theme('image_style',
				array(
				'style_name' => 'user-menu-avatar',
				'path' => $user->picture->uri,
				'attributes' => array(
					'class' => 'user-menu-avatar'
					)
				)
			);
		};
	?></

but it dosent work fork for me... I still got the error - (when upgrade drupal 7.4 to drupal 7.12)

GOT IT - proper code should look like (got this in block--system--user-menu.tpl.php file):

<?php $user = user_load($user->uid);
		if ($user->picture) {
			print theme('image_style',
				array(
				'style_name' => 'user-menu-avatar',
				'path' => $user->picture->uri,
				'width' => NULL,
				'height' => NULL, 
				'attributes' => array(
					'class' => 'user-menu-avatar'
					)
				)
			);
		};
	?></
jbrown’s picture

it isn't necessary to specify width and height as NULL - you need to clear your cache.

kkatusic’s picture

thx you @finn.lewis this NULL attribute for height and weight help me, now I don't get notice.

berenddeboer’s picture

Status: Closed (works as designed) » Active

I'm not sure why people claim running update.php fixes this. Clearly theme_image_style assumes that width and height is set, else you get a notice:

function theme_image_style($variables) {
  // Determine the dimensions of the styled image.
  $dimensions = array(
    'width' => $variables['width'],
    'height' => $variables['height'],
  );

So where is this supposedly set if I don't pass NULLs in?

berenddeboer’s picture

Status: Active » Closed (works as designed)

Sorry, just found the cause. I inherited this code, and as said above: do not call theme_image_style directly, which happened at some place. Replacing that with theme('image_style') fixed the problem.

solomonkitumba’s picture

running a drush cc all solves this problem

selva8187’s picture

#9 worked well for me .Thank you finn.lewis , you saved my time