0

I have some folder containing vertical and horizontal images and I want resize image into smaller format and lower quality.

Some of them has format:

  1. width = 3x, height = 2x - i.e. 3000x2000 or 1500x1000.
  2. width = 2x, height = 3x - i.e. 2000x3000 or 1000x1500.

How can I express such command line for convert to convert them into two smaller formats with lower quality and resize:

  1. width = 900, height = 600
  2. height = 600, height = 900

How to make this command line working only for horizontal images w > h?

convert *.jpg -resize 900x600 -quality 80 *.jpg?

I can not use such syntaxes:

  1. convert *.jpg -resize 50% -quality 80 *.jpg - all image can have differen widths.
Chameleon
  • 9,722
  • 16
  • 65
  • 127

2 Answers2

1

A couple of options...

Option 1

If you want to resize to 1500x1000 or 1000x1500 depending on the orientation, you can specify the number of pixels in the resize command using the @ area count option and the picture will retain the proportions. So, you would want 1500000 pixels in total, regardless of orientation:

mogrify -resize 1500000@ *.jpg

Option 2

You can use a little script like this to determine if each image is tall (portrait) or wide (landscape) and then do whatever processing you like on each:

#!/bin/bash
for f in *.jpg
do
   read w h <<< $(convert "$f" -ping -format "%w %h" info: )
   if [ $w -gt $h ]; then
      echo "$f is $h tall and $w wide (landscape)"
   else
      echo "$f is $h tall and $w wide (portrait)"
   fi
done

Save the script as go, then type:

chmod +x go
./go

and it will run through all your JPEGs and tell you what is what.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • I found that I can use `mogrify -path out -resize 900x900 -quality 90% *.jpg` and it resize horizontal and vertical images to 900x600 or 600x900. – Chameleon Jul 07 '14 at 08:05
0

I found that I can use mogrify -path out -resize 900x900 -quality 90% *.jpg and it resize horizontal and vertical images to 900x600 or 600x900 at once.

900x900 not mean 900 width and 900 height but scale the bigger to limit.

Chameleon
  • 9,722
  • 16
  • 65
  • 127