Search code examples
imagemagickaspect-ratioimagemagick-convert

imagemagick - convert based on aspect ratio


I need to convert an image based on its aspect ratio.

Portrait images need to be converted to 500px width.

Landscape need to be converted to 800px width.

Is this possible with a single command line.

I am trying to figure this out for a while now but the only way o found is a sh script that gets the size using identify and calls the appropriate convert.


Solution

  • if anyone is looking for this, here is how i find weather the image is landscape or portrait

    a=$(identify -format "w=%w;h=%h" l.jpg)
    eval $a
    
    if [ "$w" -ge "$h" ]
    then
      echo 'landscape'
    else
      echo 'portrait'
    fi