Use autocrop status to crop another image

I have two images A and B. I would like to use the autocrop coordinate values of A to then crop B. How to do it? I was under the impression that autocrop sends its bounding box coordinates to ${} but I am wrong.

I appreciate any help on this. Thanks.

Hello @alosca ,

What you need is command autocrop_coords:

  autocrop_coords:
      value1,value2,... | auto

    Return coordinates (x0,y0,z0,x1,y1,z1) of the autocrop that could be performed on the latest
    of the selected images.

    Default value: 'auto'

which actually does not autocrop your image, but return the autocrop coordinates that would be used to crop the image.
Like this:

foo : 
  400,400 circle. 50%,50%,100,1,1
  autocrop_coords. 0
  e "Crop coordinates: "${}
  crop. ${}
1 Like

I don’t know how I missed that command. I am always looking for answers at the List of Commands web page.

Thanks for the prompt reply and detailed answer.

1 Like

Thanks again for the help.

One step further: how do I get the individual coordinate values of ${}? I need to manipulate them in order to expand the autocrop region. So, if (x0,y0,z0,x1,y1,z1) is the autocrop region, I want then now to use (x0-u0,y0-v0,z0-w0,x1+u0,y1+v0,z1+w0) to crop the image.

Thanks for any help!

Something like this:

foo : 
  400,400 circle. 50%,50%,100,1,1
  border=10
  x0,y0,x1,y1=${"autocrop_coords. xy"}
  +crop. {[$x0-$border,$y0-$border,$x1+$border,$y1+$border]}

Thanks! I need to start using command scripts. I am not sure this would work on the command line

writing it directly on the command line works, but is much more complicated, as you have to be careful to backslash the special characters in bash, so, that’s a bit painsome:

$ gmic 400,400 circle. 50%,50%,100,1,1 border=10 x0,y0,x1,y1=\$\{\"autocrop_coords. xy\"} +crop. \{\[\$x0-\$border,\$y0-\$border,\$x1+\$border,\$y1+\$border\]\}

I have gmic 3.4.2 and it does not recognize xy for autocrop, see below. Am I outdated? :slight_smile:

`machina |2003| : gmic 400,400 circle. 50%,50%,100,1,1 border=10 x0,y0,x1,y1=${"autocrop_coords. xy"} +crop. {[$x0-$border,$y0-$border,$x1+$border,$y1+$border]}

[gmic]./ Start G’MIC interpreter (v.3.4.2).
[gmic]./ Input black image at position 0 (1 image 400x400x1x1).
[gmic]./ Draw filled circle at (50%,50%) with radius 100 on image [0], with opacity 1 and color (1,0).
[gmic]./ Set local variable ‘border=10’.
[gmic] *** Error in ./*substitute/autocrop_coords/_autocrop0/ *** Unknown command or filename ‘xy’; did you mean ‘x’?`