I am trying to figure out how to apply a class to user profile pictures in Drupal 8 to make the pictures round.

Since I am using Bootstrap 3 I can just apply image-round class in this case, but I am not sure how to add the class to the profile image.

I tried adding a class with the Field Class module, but it didn't work.

  • Just add the css yourself.. It seems like a lot of effort to go into PHP to add a class that you can duplicate. Commented Nov 6, 2017 at 19:12

1 Answer 1


In your file of your theme: "MYTHEME.theme"

Create hook_preprocess_image

 * Implements hook_preprocess_image() to add classes to the search form.
function MYTHEME_preprocess_image(&$variables) {
  ksm ($variables);
    if ($variables['style_name'] == 'thumbnail') {
        $variables['attributes']['class'][] = 'image-rounded';
  • Thank you for the reply. I tried this like this: function isabel_preprocess_image(&$variables) { ksm ($variables); if ($variables['imagecircle'] == 'thumbnail') { $variables['attributes']['class'][] = 'img-circle'; } } But for some reason it threw an error on the line : ksm ($variables);
    – Progonat
    Commented Nov 7, 2017 at 14:27
  • that's right. the KSM function is used to show the contents of a variable. To use KSM you must have the DEVEL module installed. Please comment on that line and it will work correctly. Commented Nov 7, 2017 at 15: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.