0

I'd like to check and see if all images in a directory are landscape or portrait, and them to portrait if they are in landscape. After rotating, I want to resize the images so that it is a particular resolution (118 dots per cm) and horizontal dimension (9cm).

In summary:

  • All images in portrait
  • Resolution of 118 dots per cm
  • 9cm Horizontal dimension

I know identify can pull the dimensions, but I'm not sure how to pull the individual height/width values.

Basically, I'd like to do this:

FILES=/path/to/*
for i in $FILES
identify -format "%f,%w,%h"
do
  if [%w -gt %h]
    then
    convert -rotate 90 $i

  mogrify -resize -density ?x? -resolution? -PixelsPerCm $i $i_resized.jpg
done

Ultimately, I would like to tile these to a 1m x any lenth document for printing from a plotter. Thanks!

4

2 に答える 2

3

Maybe something like this?

read f w h < <(identify -format "%f %w %h" "$imagefile")
if (( $w > $h )) ; then
    # convert
fi
于 2013-03-13T13:58:08.713 に答える
1

The image dimensions appear to be the third column in the identify output:

$ identify someimage.jpg
someimage.jpg JPEG 600x450 600x450+0+0 8-bit DirectClass 205KB 0.010u 0:00.009

So you can use cut to extract the dimensions:

f_size=$(identify $f | cut -f3 -d' ')

This would give you something ike 600x450. There are a variety of ways to separate these values. For example:

f_width=${f_size%x*}
f_height=${f_size#*x}

This is even easier with the -format argument:

set -- $(identify -format '%w %h')
f_width=$1
f_height=$2
于 2013-03-13T13:35:17.507 に答える