getkirby-v2/toolkit

Thumb crop position

jenstornell opened this issue · 9 comments

Thumb is used like this:

echo thumb($image, array('width' => 400, 'height' => 250, 'crop' => true));

Add an arg like "position => top".

For example, I crop screenshots with my template but I get the middle part but want the top part where the logo is.

Also suggested here:

http://forum.getkirby.com/t/cropping-thumbs-from-top-instead-of-center/1544

+1

some commercial Kirby Themes do this on client side (through CSS) which isn't ideal.
Alternative syntax could be:

echo thumb($image, array('width' => 400, 'height' => 250, 'crop' => 'top'));

Since this functionality is strictly bound to the 'crop' option. E.g: Having 'crop' => false, 'position' => 'top' wouldn't make any sense. And would array('width' => 400, 'height' => 250, 'position' => 'top') imply the crop option or not?

if accepted, this PR I've submitted to SimpleImage should help.

+1

Just some cases (correct me if I'm wrong):

Crop true (bool)

As it works today. When new way is implemented, it would still crop to the center when set to true. Then it would not break anything if implemented.

echo thumb($image, array('width' => 400, 'height' => 250, 'crop' => true));

Crop top

Will crop top.

echo thumb($image, array('width' => 400, 'height' => 250, 'crop' => 'top'));

Crop top left

Will crop top left.

echo thumb($image, array('width' => 400, 'height' => 250, 'crop' => 'top left'));

The PR on SimpleImage has been merged. I think if we use the crop option like described above, the only changes we need to do are in the drivers, since crop is already in the "settings string"
used to get the hash for the cache filename.

once we update the SimpleImage, we could:

handle the IM driver by replacing L295 with something like:

$map = array(
  'top'          => 'North',
  'top right'    => 'NorthEast',
  'right'        => 'East',
  'bottom right' => 'SouthEast',
  'bottom'       => 'South',
  'bottom left'  => 'SouthWest',
  'left'         => 'West',
  'top left'     => 'NorthWest'
);

$crop = strtolower($this->options['crop']);
$gravity = isset($map[$crop]) ? $map[$crop] : 'Center' ;

$command[] = '-gravity ' . $gravity . ' -crop ' . $thumb->options['width'] . 'x' . $thumb->options['height'] . '+0+0';

And handle the GD driver by replacing the current L325 with

$focal = is_string($thumb->options['crop']) ? $thumb->options['crop'] : 'center';
@$img->thumbnail($thumb->options['width'], $thumb->options['height'], $focal);

this should suffice.

(didn't test the code).

You can test the changes with this one:

https://github.com/rasteiner/test_toolkit_thumbs

+1 on making this a core feature.

I've got many projects in where it would be really valuable to be able to do some "art direction" here, e.g. when used in combination with a custom field "Crop Position", based on which you would be able to set the crop position in the template.

Hope this feature will eventually make it.

I agree! But in the meantime you should really check this out:
https://github.com/flokosiol/kirby-focus

On Fri, Nov 4, 2016, at 04:55 PM, Philipp Sterker wrote:

+1 on making this a core feature.
I've got many projects in where it would be really valuable to be able
to do some "art direction" here, e.g. when used in combination with a
custom field "Crop Position", based on which you would be able to set
the crop position in the template.
Hope this feature will eventually make it.
— You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub[1], or mute the
thread[2].

Links:

  1. #99 (comment)
  2. https://github.com/notifications/unsubscribe-auth/AABf1GM1y6Ch14I2w35BtZV8PoBkj_A4ks5q61VkgaJpZM4F0DhH

@bastianallgeier that's great and keeps my hopes up :)

And yep that's what I ended up using – Kirby-Focus is an excellent plugin and totally fits my needs for now.

Until this is implemented here is a temporary fix for it, as plugin:

https://github.com/jenstornell/kirby-crop-top

maybe kirby could switch image lib to one that supports positioned croping and more? suggested it here:

getkirby/kirby#576