MrGcGamer wrote: ↑
So basically what I want to do is trimming an image but keep its aspect ratio... is that possible using imagemagick and without setting custom values for each image?
To give you the best answers we need to know what version of ImageMagick you're using and which OS you're running on. Maybe post some images of exactly what you're trying to accomplish. The solutions depend on a lot of things you haven't told us.
Generally, with ImageMagick the operation "-trim" does a particular thing, which is to shave off rows and columns of same-color pixels from the outer edges of an image. It can't maintain the aspect ratio. If that's what you want, it can probably be done, but not just by trimming, and could get more complicated.
However, there are several ways with IM to chop and shave and otherwise modify the dimensions of the viewport while keeping the aspect ratio, mostly by setting the operations' values as percentages. Here are some examples...
Code: Select all
convert logo: -gravity center -extent 80% result1.png
convert logo: -shave 10% result2.png
convert logo: -gravity northwest -chop 20% result3.png
The first command uses "-gravity center" and "-extent" to reduce the viewport by 10% on every side. That essentially crops out the center 80% of the input image and keeps the input's aspect ratio. The "-gravity" setting can be changed to keep the upper-left, lower-right, left-center, etc. piece instead of the very center.
The second command does exactly what it looks like. It shaves 10% off each of all four sides. The result is the same as the "-extent" operation with "-gravity center", but "-shave N%" affects all four sides regardless of the "-gravity" setting.
The third command uses "-chop", and will remove 20% from the top and left sides of the image. Adjust the "-gravity" setting to make it chop any two adjacent sides. This also maintains the input aspect ratio, but it only works on two adjacent sides at a time. It can't keep a piece from the center.