43

Using Imagemagick, I'd like to convert a batch of PNGs to a fixed height of 1080px and a proportional width. With proportional I mean this: If the original Image is scaled down 16.8% to 1080px, the width also needs to be scaled down by 16.8%.

Any way of using convert without having to calculate the exact geometry before (using identify and some bash calculation shenanigans) ?

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
Christian
  • 1,212
  • 1
  • 15
  • 30

3 Answers3

82

Try this:

convert -resize x1080 {from_path} {to_path}
DarthJDG
  • 16,511
  • 11
  • 49
  • 56
Dmitri Gudkov
  • 2,093
  • 16
  • 15
7

Image geometry is an option described to use with -resize

xheight Height given, width automagically selected to preserve aspect ratio.

So you only have to specify the height

Bernhard
  • 3,619
  • 1
  • 25
  • 50
DanielB
  • 19,910
  • 2
  • 44
  • 50
-1

There is one additional example. give it some values to the resize parameters and it'll automatically resize your image. Plus you can chose other parameters (gravity center or crop etc.).

  convert image_example: \
          -resize x160 -resize '160x<'   -resize 50% \
          -gravity center  -crop 80x80+0+0 +repage  image_example.jpg

Cheers

Andy McRae
  • 525
  • 7
  • 15