I have a small one-liner in terminal which is to write the pixel count of many JPEG files to a text file:
find . -name *.jpg -exec convert {} -format "%[fx:w*h]" info: \; > sizes.txt
It actually does, but some of the numbers are in scientific notation, like here:
949200
960000
1.098e+06
1.038e+06
1.1664e+06
1.0824e+06
831600
What is the most robust / elegant way to have the commands output just in decimal notation, like in the following lines?
949200
960000
109806
103806
1166406
1082406
831600
I was wondering if you would do this within the ImageMagick fx part or rather pipe the output to another command for conversion. Thanks!
According to http://www.imagemagick.org/script/escape.php there is no obvious way to get other number formats with the %fx: directive, so a command line solution is necessary.
Converting the w*h scientific notation output will lose you significant digits, so better output w and h separately and multiply.
Using bc this would be:
find . -name '*.jpg' -exec convert {} -format "%w*%h" info: \; |bc
To have ImageMagick print numbers larger than one million without truncating them to exponential (scientific) notation, use the -precision n option. The default precision is 6. I suggest setting it to 12, which allows numbers up to 1e+12 (a 1 followed by twelve zeros).
$ convert xc: -precision 12 -format '%[fx:1000*1000]\n' info:-
1000000
$ convert xc: -precision 6 -format '%[fx:1000*1000]\n' info:-
1e+06
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With