zimpff
zimpff

Reputation: 1

UNIX Command to add image dimensions to filename?

I am sure this can be done somehow, but my limited knowledge with the UNIX command line needs a nudge here. What I want to do is the following:

  1. There is a directory full of PNG files
  2. Determine the image dimensions width and height of each image file
  3. Rename the file foo.png to [width_value]x[height_value]_foo.png

Any lead would be appreciated.

Upvotes: 0

Views: 245

Answers (1)

KevinDTimm
KevinDTimm

Reputation: 14376

for i in `ls *.png`
do
   params=`get parameters from $i`
   mv $i params$i
done

left as an exercise for the OP is the program to get the information from the png file

Note that sips is the bsd command to get image information so:

height=`sips -g pixelHeight $i`
width=`sips -g pixelWidth $i`
mv $i $heightX$width$i

Upvotes: 1

Related Questions