The goal of this module is to provide some control over automatic image cropping in SilverStripe.
Problem: SilverStripe crops all images from the centre. If the subject is off-centre, it may be cropped out.
Solution: FocusPoint allows you to tag the subject in an image and ensures it is not lost during cropping.
Download and extract, rename the module folder 'focuspoint', place it in your project root and run a dev/build?flush=1.
Note: Prior to SilverStripe v3.1.9 dev/build?flush=1 did not flush .ss template files. If using SilverStripe 3.1.8 or earlier you'll need to flush the templates on a page URL e.g. yoursite.dev/?flush=1.
Fun fact: you don't generally need to manually flush template files in SilverStripe after changing them - except when they are new or are rendered via
<% include %>.
When you edit an image in the CMS there should be an extra 'Focus Point' field. Click on the subject of the image to set the focus area and save the image.
Use just like $CroppedImage, but use $CroppedFocusedImage instead.
You can specify that images should not be upscaled by passing a third argument:
<% with $SomeImage %>
<img src="$Link" alt="" />
<% end_with %>
Try something like this to get a full-screen background image that preserves your focus point.
<% with $BGImage %>
background-position: $PercentageX% $PercentageY%;
<% end_with %>
If you are caching page content that includes a CroppedFocusedImage and you edit the image (i.e. by changing the focus point) but not the page, you may want to invalidate the page's cache as the updated CroppedFocusedImage will have a different filename. Gordon Banderson has written a robust extension to help you achieve this.
SilverStripe FocusPoint provides an easy and automated way to get better results when forcing an image to be a different aspect ratio. I have some vague plans to offer more fine-grained control over individual crops in the future, but until then I recommend checking out Will Morgan's SilverStripe CropperField as an alternative.
If the focus point field shows a non-interactive image and a text field with a comma in it, make sure the module folder is named 'focuspoint' and try visiting yoursite.dev/?flush=1 again.
As a cache-busting mechanism this module includes approximate focus point coordinates in generated filenames. This means that if the focus point is updating correctly in the CMS but you're not seeing images change on your website, it's likely that you're viewing cached HTML output and need to invalidate that to see the updated image.