Score:0

How to resize an image using ImageMagick

cn flag

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?

Hannu avatar
ca flag
https://askubuntu.com/a/25134 - after following your link. Seems `!` signifies `don't keep aspect ratio`
Saeed Neamati avatar
cn flag
@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.
Hannu avatar
ca flag
Yes!? So, as I understand the examples; do NOT include a `!`,
Saeed Neamati avatar
cn flag
@Hannu, then what is the command? I'm confused. I have not included `!` in my question.
Score:2
ru flag

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.

Saeed Neamati avatar
cn flag
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?
codlord avatar
ru flag
@SaeedNeamati I updated my answer above.
Saeed Neamati avatar
cn flag
thank you so much.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.