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?

4
  • askubuntu.com/a/25134 - after following your link. Seems ! signifies don't keep aspect ratio
    – Hannu
    Dec 26, 2022 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. Dec 26, 2022 at 11:28
  • Yes!? So, as I understand the examples; do NOT include a !,
    – Hannu
    Dec 26, 2022 at 11:30
  • @Hannu, then what is the command? I'm confused. I have not included ! in my question. Dec 26, 2022 at 11:32

1 Answer 1

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.

3
  • that worked great. Now I'm in a situation that I need to resize based only on height. If I provide a single value, it takes it as the width parameter. What syntax should I use? Dec 29, 2022 at 4:19
  • @SaeedNeamati I updated my answer above.
    – codlord
    Dec 29, 2022 at 14:04
  • thank you so much. Dec 30, 2022 at 13:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .