In the latest ImageMagick, it can crop by the aspect ratio with the offset ,
For example -crop 1:1+500+0
However, with the offset, the reasult is not always keep the maxium area for the aspect ratio we want.
For another example, let's I have a 1400x1400 jpg file.
And I use
magick convert in.jpg -crop 1:1+50+0 out.png
which the resolution of the output file would be 1350x1400.
Any solution for always keep to crop the maxium area of the aspect ratio we assigned?
I do not believe that the aspect crop was designed for offsets. It was my suggestion to do the aspect crop and the IM developer and I never considered including offsets at the time. The idea was to just center crop so that the image had the desired aspect. If you want to offset, then I think you need to use -crop first. But I will defer to the IM developers for further comments. Perhaps he included that concept and I did not know about it.
It would be easy enough to account for the offset if @fmw42 agrees. Fred what do you think? Does supporting aspect ratio geometries that respects offsets makes sense and would it likely be useful?
I am not sure what the OP wants. If it is just crop first to the offset and then crop that to the aspect ratio specified, that is OK and would save one extra crop. But it can be done by -crop 1350x1400+50+0 +repage -crop 1:1 +repage. I suspect doing it either way would be useful. So if it is not hard to do what I have suggested here and is what the OP really wants, then go ahead and do it. But you then probably need to respect the gravity when doing the offset part of the crop and then when doing the aspect part of the crop, go back to center cropping. Is that what the OP had in mind? Perhaps he needs to explain further with respect to when the offset part would happen and what he expects with respect to gravity? Are we respecting gravity now for the aspect crop or just doing it always center relative.
I was thinking the
magick convert -crop 1:1+x+y -gravity center
is working same with
magick convert -crop +x+y
magick convert -crop 1:1 -gravity center
Sorry for my English.
I'll try my best.
I have many pictures which they are not fixed resolution.
I make crope center square pictures for the cd cover art.
Sometimes I would like to adjust the offset for not to cut some texts or faces.
So I use it with command line find the best offset for the resault which I want.
And than I notice that even I assigned the aspect ratio the resault it not awayls the ratio I assigned. (maybe a little confused)
Now I just work arround for asighed the output weight and height (which I don't want)
The gravity setting must come before the crop. Settings always come before the operator. IM 6 is forgiving, but IM 7 is not. Even in IM 6, this likely would not work with the gravity after the crop. Also in IM 7, use magick only, not convert and not magick convert. If I understand your commands for
-crop +x+y
you have not specified a gravity so it takes it as -gravity northwest
So I take it that you want to crop the offsets according to -gravity northwest, then crop the aspect relative to -gravity center.
But someone else might want to crop offsets -gravity south or north or east or west, etc first. Then center crop the aspect gravity center, or even crop both relative to gravity northwest, etc.
So it seems to me better to do two separate crops so that one has full flexibility on the gravity setting for both parts.
The aspect crop is already gravity relative. So your command would be currently.
magick in.jpg -crop +x+y +repage -gravity center -crop 1:1 +repage out.jpg
This will do a -gravity northwest crop the +x+y and then a center crop to aspect 1:1.
So it is equivalent to
magick in.jpg -gravity northwest -crop +x+y +repage -gravity center -crop 1:1 +repage out.jpg
My recommendation is to leave it as is for full flexibility, thus requiring two crops if one wants to use offsets.
Thanks !!! @fmw42 It solve my problem. So maybe I can close this issue.
Sorry for one more question is : does crop two times in one command loss the quality doubled by processing with the jpeg file?
or if the output format is a lossless format then all of the crop processing is lossless?
You do not lose quality twice with two crops. Once the JPG image is read into memory it is decompressed to full resolution and and quality. It is only recompressed at the end of the command line when it is written to disk. The IM developer can correct me if I am wrong about that. With non-lossy compressed images, such as PNG. There will be no loss of quality.