jarednova/timber — pull request #159 by mmikkel (2014-02-17 12:03:34+00:00)
Title: Crop position and force resize parameters for TimberImage resize filter

Hello Jared,

This is a follow-up to my feature request @ https://github.com/jarednova/timber/issues/53. I kind of needed this functionality right now, so I decided to take a stab at it myself.

The default crop position at top/left for the resize filter won't always be desirable – and sometimes you don't want to crop the image at all.

My pull request implements a third parameter @crop to the resize filter:

```php
post.image.get_src|resize(100,100,'center');
```

The crop parameter has the following possible values:

default (string) – crop from top/left (like before, this is the default value)
center (string) – crop from center
false (boolean) – don't crop

Ideally the @crop parameter would take an array of positions as well – as discussed in this WP trac: https://core.trac.wordpress.org/ticket/19393 – something like this:

```php
post.image.get_src|resize(100,100,['left','center']);
```

I don't have the time to look into that right now, though.

Note: this pull request implements a fourth parameter @force_resize to the resize filter. Setting force_resize to true will unlink any exisiting image, hence regenerating the image on every pageload. Kind of scary, but useful for dev/testing purposes (even moreso if the crop position can be more flexible in the future as outlined above).

Thanks and best regards,

Mats