Improvement of `autocrop` and `autocrop_coords`

Hello there,
Just a quick message to describe some cool improvements I’ve made today on commands autocrop and autocrop_coords.
These commands allows respectively to automatically crop the content of an image, according to a uniform background color (either specified or automatically guessed), or to just return the corresponding cropping coordinates without actually applying the crop operation.
Like this:

$ gmic 400,400,1,3 fill_color 64,128,255 ellipse 50%,50%,120,120,0,1,255 +autocrop

Here’s what I did today:

  • Basically, I’ve recoded both commands autocrop and autocrop_coords from scratch, as stdlib commands.
  • This means autocrop won’t be a native command anymore. Expect then a bit of slow down (still reasonnable I think) when using autocrop. It’s sometimes even faster on larger image, as it’s now implemented as a multi-threaded operation.
  • Command autocrop_coords was already a stdlib command, so its state does not change.
  • The interesting thing is that I’ve been able to add a new axes argument, that can be specified to tell G’MIC along which axes the autocrop must be done (including the spectrum axis c which was not possible before). So for instance :
$ gmic shape_cupid 300 frame xy,30,0 +autocrop[0] x +autocrop[0] y +autocrop[0] xy 


Having this option to specify which axes must be considered for the autocrop operation is way more flexible than before.

  • This new axes option also exists for command autocrop_coords.

Well, that’s it. I’ve updated the stdlib , so a simple $ gmic update should make this new autocrop_coords available.
As for the autocrop command, as it was a native one before (therefore not replaceable by a stdlib command), you’ll have to update your G’MIC binaries to be able to use it with the new axes option.
Perfect timing: I’ve updated the pre-release binaries also today: Index of /files/prerelease

Let me know what you think about this.

As usual, I hope it doesn’t hurt my filters. Anyway, I like the new changes, though I don’t know when I will take advantage of it. This is one I rarely use though.

The reimplementation of these commands should be perfectly backward compatible with the arguments used for the previous commands. If you encounter issues related to these new autocrop, please let me know.

I found a potential issue, but not on most .gmic file.

In kristian_jarventaus.gmic file, there’s a lot of autocrop c. And as you said, you allowed c as an argument.

That’s right, thanks for noticing this!
Fix: