Reputation: 167
I have learned that I can get the width and height of an image using:
identify image
How do I extract the width and height from the result of identify and store it in a variable ?
Upvotes: 3
Views: 1658
Reputation: 113844
To set shell variables width
and height
to the width and height of an image, use:
width=$(identify -format '%w' "$filename")
height=$(identify -format '%h' "$filename")
The variables width and height can be manipulated using all the standard bash arithmetic operations. For example:
$ width=$(identify -format '%w' "$filename")
$ echo "w=$width 2*w=$((2*width)) 5+3*w=$((5+3*width))"
w=400 2*w=800 5+3*w=1205
Upvotes: 7