Using the Focal Point Module for Images in Drupal 8
You most likely created image styles with Drupal’s “Scale and crop” image effect. This style allows you to display large images on a smaller scale and save precious screen space.
There is one issue with such styling though. Often the most interesting point of the image gets chopped off. The “Focal Point” contrib module helps avoid this issue.
In this tutorial, you will learn to use this module to select the most important portion of the image you would like to show to your readers.
There is always a limited amount of space on a screen. So when you insert an image in your posts, you have sometimes either to crop it or to scale and crop it. By default, Drupal provides image styles, which you can create and configure.
This is a good solution, but sometimes it’s kind of rigid. You only have the focal point, the part of an image that will be retained during the crop, for all images with that style. Sometimes the most interesting part, the part you want your readers to see, is not in the center.
Example:
If we crop this image with the anchor in the center of it we will have this result:
We should set the anchor point to the right of the image style. But, what if we want to draw the attention of the reader to the left of the image in the next post? That would certainly complicate everything.
For these cases, you have the contributed module Focal Point available. Focal Point allows you to choose the most important portion of the image to show to your readers. In this tutorial, you will learn how to do that.
Let’s start!
Step #1. Install and enable the module
- Before installing the Focal Point module, install first the Crop API module. This is a required dependency.
Step #2. Configure the Image Style
- Click Configuration > Media > Image Styles
Click Add image style
- Give your image style a proper name. In this case, I’m going to call it Square (300×300). It’s a good practice to include the dimensions of your image style in the name so that you have a better orientation when selecting image styles for your displays (for example in Views)
- Click Create new style
- Select the Focal Point Crop effect
- Click Add
- Now set the dimensions for the cropped image, in this case, 300x300px
- Click Add effect
The new image style has been created. Let’s test it!
Step #3. Set the image style as the default display
We’re going to apply this image style to the Article content type
- Click Structure > Content Types > Article > Manage display
- Click on the cogwheel on the right of the Image field
- Choose the newly created style Square (300×300)
- Click Update
- Click Save
Step #4 Create an Article
- Click Content > Add content > Article
- Upload an image
- After uploading you will see a little cross on the preview thumbnail
- Drag this cross and place it wherever you want to set the focal point of the image
- Save the article and view the result
- Don’t like the result? No problem! Edit the article and drag the cross until you get the expected image in your article.
This handy module gives the site editors a great flexibility! I hope you enjoyed reading about the Focal Point contrib module.
Leave your comments below. Thanks!
Great find! This will come in handy in a lot of scenarios!
Thank you, Hamza. Great to hear you found this post handy!
I share the same opinion Hamza. Thanks for your feedback!
Great tutorial … glad you like the module 🙂
Cheers, bleen.
Thank you very much bleen. It’s a nice module!
Doesn’t seem to work with media entities
Hello Paul,
to be honest, I haven’t dealt with the Media module that much to give you an accurate answer.
I read about some solution here:
https://www.deeson.co.uk/labs/drupal-focal-point-module-making-most-your-images
but I guess that’s a D7 solution.
I’m doing research. I’ll get back to you when I’ve found something.
If it should be an issue related to the new Media features in Drupal, you can watch this very informative video with Steve’s explanation:
https://youtu.be/5o5CrWUi1Jg
Hello Paul,
Basically you have to do the following:
1. Install the media entity image module
2. Create a media bundle for images
3. Add an image field to this bundle
4. Set the form display in this bundle for this particular field to focal point (of course you have previously created the image style)
5. Add a field of type Other – Media (type of item to reference) to your content type
6. Create the media content with your image. You’ll upload the image and set its focal point here
7. Create your content and reference the media content you created in step 6
That’s it!
Hope this explanation helps!
On this focal point module there seems to be an issue with the size of the original image grows for example: when I upload an image to the CMS area it starts out at 222kb and I check the download size in the browsers “Network” tab on Developer tools. Slightly higher or lower here for desktop. But then I simulate a mobile device such as tablet or responsive and the size via Network tab grows from the 222 to 765kb. I have tried adjusting the format/Configure Responsive Image Styles in many ways but the image seems to grow no matter what. Any insight into a possible solution would be helpful
I’m not sure this has to do with focal point, but should definitely open an issue at https://www.drupal.org/node/add/project-issue/focal_point …. I have some ideas on how you can troubleshoot
Hello Bleen,
thanks for your support. I opened an issue in the issue queue.
Hello Gerry,
I tried to replicate this behaviour, but I get the same image sizes for the focal point images and the normal images (cropped with the core functionality) in desktop and in mobile as well. Maybe it’s an issue with the image manipulation library as described here: https://www.drupal.org/project/focal_point/issues/2931884
Thanks Jorge Montoya.
That’s very good tutorial, I setup in my site https://www.timnhanhvietuc.com/ that works awsome.
Thanks again.
Great, is there a way to set a default focal point for the image style?