I don't think -crop allows fx computations for arguments like -distort or some other functions now do. However, you can make some long complex variables that have fx calculations.
For example:
This works to get the center half image:
infile="logo:"
outfile="logo_crop.jpg"
ww=`convert $infile -format "%[fx:w/2]" info:`
hh=`convert $infile -format "%[fx:h/2]" info:`
convert $infile -gravity center -crop ${ww}x${hh}+0+0 +repage $outfile
And this does, but is really no better:
infile="logo:"
outfile="logo_crop.jpg"
convert $infile -gravity center \
-crop $(convert $infile -format "%[fx:w/2]" info:)x$(convert $infile -format "%[fx:h/2]" info:)+0+0 \
+repage $outfile
But you cannot do the following as it ignores the fx calcs and gives the output same size as input.
But it would be a nice enhancement to -crop or better yet to geometry in general.
infile="logo:"
outfile="logo_crop.jpg"
convert $infile -gravity center -crop %[fx:w/2]x%[fx:h/2]+0+0 +repage $outfile
But this works. see
http://www.imagemagick.org/Usage/distor ... t_viewport
infile="logo:"
outfile="logo_crop.jpg"
convert $infile -set option:distort:viewport %[fx:w/2]x%[fx:h/2]+%[fx:w/4]+%[fx:w/4] \
-distort SRT 0 +repage $outfile
(
Too bad viewport does not seem to be -gravity sensitive, so you have to provide the offsets)
You can fill in with your ratio comparison calculation in place of my simply taking half the image.
Also, depending upon your system, you may have to quote the expressions as either:
convert $infile -set option:distort:viewport '%[fx:w/2]x%[fx:h/2]+%[fx:w/4]+%[fx:w/4]' \
-distort SRT 0 +repage $outfile
or
convert $infile -set option:distort:viewport '%[fx:w/2]'x'%[fx:h/2]'+'%[fx:w/4]'+'%[fx:w/4]' \
-distort SRT 0 +repage $outfile
My system does not seem to need it. But Anthony can give more advice about using fx calcs with viewport