0

From How to easily resize images via command-line? I know I can use this command to resize an image in bash:

convert -resize 1024X768  source.png dest.jpg

But I'm stuck at only providing the width and keeping the aspect ratio.

man convert does not provide any help for -resize flag.

I want something like convert -resize 1024 -keep-ratio source.png dest.png

What would be the command?

Tom Newton
  • 105
  • 7
Saeed Neamati
  • 497
  • 1
  • 5
  • 16
  • https://askubuntu.com/a/25134 - after following your link. Seems `!` signifies `don't keep aspect ratio` – Hannu Dec 26 '22 at 11:18
  • @Hannu, I **want** to keep the aspect ratio. None of the commands in the answer link you mentioned do that. I need to **keep** aspect ratio, and I need to only provide the width. – Saeed Neamati Dec 26 '22 at 11:28
  • Yes!? So, as I understand the examples; do NOT include a `!`, – Hannu Dec 26 '22 at 11:30
  • @Hannu, then what is the command? I'm confused. I have not included `!` in my question. – Saeed Neamati Dec 26 '22 at 11:32

1 Answers1

2

convert -resize by default does keep the aspect ratio (unless ! is specified). So to resize based on width alone you would just need to do: convert -resize 1024 source.png dest.png

To convert based on the height alone for example: convert -resize x768 source.png dest.png

-resize takes the Geometry parameter. Take a look at the docs I linked as well as resize examples.

codlord
  • 2,141
  • 7
  • 19