Skip to content

Commit

Permalink
Added FP_Image_Cached class
Browse files Browse the repository at this point in the history
Fixes #44
  • Loading branch information
jonom committed Jul 26, 2017
1 parent 7afe1e9 commit a2a2ce5
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The goal of this module is to introduce some basic art direction to control how

## Requirements

SilverStripe 3.3+ (SS 3.1+ support available in earlier releases)
SilverStripe 3.6+ (SS 3.1+ support available in earlier releases)

## Documentation

Expand Down
21 changes: 12 additions & 9 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ Image:
extensions:
- FocusPointImage

#FocusPointField:
# debug: true
# max_width: 500
# max_height: 300
#Injector:
# ImagickBackend:
# class: "FPImagickBackend"
# Image:
# class: FPImage
# FocusPointField:
# debug: true
# max_width: 500
# max_height: 300

# Injector:
# Image:
# class: FPImage
# Image_Cached:
# class: FPImage_Cached
# ImagickBackend:
# class: "FPImagickBackend"
18 changes: 11 additions & 7 deletions code/FPImage.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

/**
* Override default cropping methods with FocusPoint versions
*
* @extends Image
*/
class FPImage extends Image
{
public function Fill($width, $height)
Expand All @@ -23,12 +28,12 @@ public function CropHeight($height)
}
}

/*
// This is required to ensure manipulated images get their methods overidden too,
// but it doesn't work because Image_cached isn't compatible with the injector.
// Not having this in place means chained method chaining doesn't work properly
// e.g. `$Image.ScaleHeight(200).CropWidth(200)` will not use $FocusCropWidth.
class FPImage_cached extends Image_cached {
/**
* Ensure manipulated images get their methods overidden too, for method chaining
*
* @extends Image_cached
*/
class FPImage_Cached extends Image_Cached {

public function Fill($width, $height) {
return $this->FocusFill($width, $height);
Expand All @@ -46,4 +51,3 @@ public function CropHeight($height) {
return $this->FocusCropHeight($height);
}
}
*/
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"homepage": "http://jonathonmenz.com"
}],
"require": {
"silverstripe/framework": "^3.3"
"silverstripe/framework": "^3.6"
}
}
4 changes: 3 additions & 1 deletion docs/en/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ You can swap out the `Image` class using the [injector](https://docs.silverstrip
Injector:
Image:
class: FPImage
Image_Cached:
class: FPImage_Cached
```
This will automatically upgrade the built-in cropping methods so that they give you focused output. Caveat: this doesn't apply to chained image methods unfortunately due to a limitation with injector support in the `Image_cached` class.
This will automatically upgrade the built-in cropping methods so that they give you focused output.
## Method chaining
Expand Down
8 changes: 4 additions & 4 deletions docs/en/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ When you edit an image in the CMS there should be an extra 'Focus Point' field.

Use just like existing cropping functions but swap out the names:

- $Fill --> $FocusFill
- $FillMax --> $FocusFillMax
- $CropWidth --> $FocusCropWidth
- $CropHeight --> $FocusCropHeight
- `$Fill` --> `$FocusFill`
- `$FillMax` --> `$FocusFillMax`
- `$CropWidth` --> `$FocusCropWidth`
- `$CropHeight` --> `$FocusCropHeight`

Or use the existing names... see 'Method replacement' in [Advanced usage](advanced-usage.md).
4 changes: 4 additions & 0 deletions docs/en/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ If the focus point field shows a non-interactive image and a text field with a c
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.

Other SilverStripe modules can also prevent images being regenerated when the focus point is changed. You can work around this by telling SilverStripe to [delete resampled versions of an image when its focus point is changed](#flush-generated-images-on-focus-point-change).

### Warning messages and broken images after upgrading to SilverStripe 3.6+

SilverStripe 3.6 introduced Injector support for `Image_Cached`. If you're using the FPImage class through the Injector, you now need to also use the `FPImage_Cached` class. See [Method replacement](advanced-usage.md#method-replacement).
2 changes: 1 addition & 1 deletion templates/FocusPointDebug.ss
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<img src="$link" alt="" width="$Width" height="$Height" />
<div class="crosshair" style="left:$PercentageX%; top:$PercentageY%;"></div>
</div>
<p class="info">$Name<br>FocusX: $FocusX, FocusY: $FocusY</p>
<p class="info">$Name<br>FocusX: $FocusX, FocusY: $FocusY, Class: $ClassName</p>
</div>

0 comments on commit a2a2ce5

Please sign in to comment.