I'm using the following code to generate a thumbnail and it's URI. The URI works on its own (though it 404's) but whenever I add theme_image_style function it gives a fatal error: "Unsupported operand types in /theme.inc on line 1088"

$image_fields_src = array_column($image_fields, 'uri' );

// thumbnail uri
$thumburi = image_style_path('thumbnail', $image_fields_src[0]);
// generate thumbnail
$thumbnail = theme_image_style('thumbnail', $thumburi );
  • what is your drupal version ? 7 or 8 ? where do you use the codes? – Yusef Jan 7 '18 at 18:04

According to theme_image_style page you tried wrong parameters,

as an example, your code should be something like the following snippet

$variables = array(
        'style_name' => 'thumbnail',
        'path' => $image_fields[LANGUAGE_NONE][0]['uri'],
        'width' => $image_fields[LANGUAGE_NONE][0]['width'],
        'height' => $image_fields[LANGUAGE_NONE][0]['height']
$thumbnail_image = theme_image_style($variables);

and in short

$thumbnail_image = theme('image_style', array(
        'style_name' => 'thumbnail',
        'path' => $image_fields[LANGUAGE_NONE][0]['uri'],
  • Thanks. Why do I need to add width/height parameters? Shouldn't width and height already by assigned since thumbnail is a default size? – Sam Jan 8 '18 at 11:31
  • Also, I don't want to print the image, just have it accessible by other functions. – Sam Jan 8 '18 at 11:41
  • 1
    @Sam height and width assigned by your image styles dimension, defaults for thumbnail is 100x100, you can see them on admin/config/media/image-styles , ok instead I print it I'll put it on a variable and do what you want with it. – Yusef Jan 8 '18 at 12:28
  • thanks. Is simply setting it as a variable going to create the thumbnail (on the server) ? Because I seem to be getting 404s from the path unless I actually print the image. – Sam Jan 8 '18 at 13:57
  • @Sam you're welcome, yes, finally you must render it ( by print, echo ,etc) in your theme. – Yusef Jan 8 '18 at 15:57

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.