Focus // Define an image focus point

I’ve been using your amazing plugin to cut images in half using the $image->focusCrop() method. It was working fine with GD, but after switching to IM, it doesn’t seem to work anymore. Anyone else experiencing the same issue?

I’m using Kirby 2.5.2 and Focus 1.0.9.

Does it work with IM and the original crop() method instead of focusCrop()? Be aware that the third parameter differs and make sure the thumbs don’t exist already in your thumbs folder.

I’ve cleared my thumb directory before testing. The original crop() method doesn’t work either…

My live server runs on php 7.0 instead of 5.6.10 like my local server. I’ve just tested it on that live server and IM does work over there.

Alright. If crop() doesn’t work either, the issue is not related to Focus. Good news for me :stuck_out_tongue_winking_eye:

Maybe your local IM setup is not correct? You could test it by creating a simple php file on your local server with a basic IM command like …

<?php
  exec('/usr/local/bin/convert input.png -strip -crop 100x100+0+0 ^ -resize 50x50 -quality 90 -limit thread 1 output.png'); 
?>

You may need to adjust the path to IM and make sure the input.png exists in the same folder. If it works (output.png is generated), the IM setup is ok.

You might have to set the path to the convert bin manually in your config:

thumb::$defaults['bin'] = '/usr/local/bin/convert'; // whatever that path is

The code @flokosiol mentioned does work on my local server. As well as resizing an animated .gif in Kirby.

I re-checked everything, but it still works for me:

  • Kirby Starterkit 2.5.2
  • Focus 1.0.9
  • PHP 5.6.20 (and also 7.0.5)
  • ImageMagick 6.9.4-3

What happens if you remove the plugin? Does crop() work again?

Maybe you can find a hint in your Apache error log?

I’m using your plugin on a soon to be released site. It’s a brilliant plugin in all its simplicity but with a lot of power. Our client loves being able to define focus point to the large hero images so the important parts of the image is always shown on desktop or mobile.

One of the best plugins for the Kirby ecosystem in my opinion.

For the record, I rarely use your plugin to crop the images to thumbs on the server. Instead I use your plugin to output the coordinates of the focus point for images used as a background image or an image with the object-fit: cover; css property.

Example:

<div style="background-image: url(image.jpg); background-size: cover; background-position: 40% 80%;"></div>

<img src="image.jpg" style="object-fit: cover; object-position: 40% 80%;" />

For fullscreen images it’s better to let the browser crop the images depending on screen size and orientation (portrait/landscape).

6 Likes

Thanks for the kind words!

I should definitely add an example of your background-image code to the README.

1 Like

is using the exec command necessary? at some hosts i have experienced that the exec command is disabled…

The Kirby IM driver also uses the exec command. You can do without the exec command if you have the ImageMagick PHP extension installed, I think.

I extended the Kirby IM driver and tried to keep it as close to the original as possible. But you should be able to override it and adjust it to your needs, I think.

i was trying to play around to see if IM performs better in terms of speed or quality but given exec is not available i changed it to use gd again.

Great plugin.

Is it possible to use this plugin for user avatars? How would that be done?

@thewebprojects Have you tried chaining it onto the end of the avatar code? Cant see why it wouldn’t work. See the docs.

Not tested but i think something like this should work…

<?php if($avatar = $site->user('bastian')->avatar()): ?>
<?= $avatar->focusCrop(200) ?>
<?php endif ?>

Don’t know if you can add file meta data to avatars though, in order to store the coordinates. However focus crop does allow you to override these.

You could take the author approach from the cookbook instead, which should give you more flexibility.

No, this is not possible.

Appart from the missing meta data file, it looks like custom file methods can’t be used for avatars. I did a quick test and it doesn’t work at all. Sorry.

I thought as much. To be honest avatars, traditionally, are just meant to be a small badge of a person or a logo. I think the author approach from the cookbook is probably the best solution.

1 Like

Ok. Thanks for replies.

3 posts were split to a new topic: Error when using the Focus plugin