How supress "jpegtopnm: WRITING PPM FILE" etc within output of jpegtopnm[Solved]

47 views Asked by At

I want to see the sizes of images within a directory. For this purpose I do

$ for file in *.jpg; do jpegtopnm $file | pnmfile; done

Then I can see

jpegtopnm: WRITING PPM FILE
stdin:  PPM raw, 960 by 1280  maxval 255
jpegtopnm: WRITING PPM FILE
stdin:  PPM raw, 960 by 1280  maxval 255
jpegtopnm: WRITING PPM FILE
stdin:  PPM raw, 1200 by 1600  maxval 255

and so on.

I would like to see

  960 by 1280
  960 by 1280
 1200 by 1600
.............

How one can do this?

Answer

The command jpegtopnm is a part of netpbm - package of graphics manipulation programs and libraries:

 $ apt-file -l find pnmfile
 netbpm

Then we must read "man netbpm":

-quiet Suppress all informational messages

Thus we solved our problem:

 $ for file in *.jpg; do jpegtopnm $file -quiet | pnmfile | cut -c 16-28; done
 4000 by 3000  
 2592 by 1944  
 4000 by 3000
 ............

About "cut -c 16-28".

This is a filter that selects characters from 16 to 28 in a string

"stdin: PPM raw, 960 by 1280 maxval 255".

If you have at your directory images with different sizes such as 4000x5000, 300x400, 2x3, 40x67 etc it won't work properly. For that reason you have to use more complicated way. It is a "cut" filter by fields(-f). The field separator will be a space character(-d ' ').

$ for file in *.jpg; do jpegtopnm $file -quiet | pnmfile | cut -d ' ' -f 3-5; done
700 by 900
65 by 40
2 by 3
7000 by 9000
4000 by 3000
............
0

There are 0 answers