Page 1 of 1
how to get de-facto bits-per-pixel image property via identify
Posted: 2017-11-10T02:15:18-07:00
by AlexPUA
The goal is to get value (file_size_in_bytes)/(image_height*image_width) in massive (Windows !) batch.
There are two problems (for me as a beginner):
- I found no -format option to get "always integer" filesize in bytes (%[size] give KB or MB values) to do math externally
- "obvios" calculations via
fx:
identify -format "%[width] %[height] %[size] %[fx:b/(w*h)]" filename.jpg
gives uncorrect result because
%b file size of image read in is not the file size but usage of
%[size] impossible in
fx:
Re: how to get de-facto bits-per-pixel image property via identify
Posted: 2017-11-10T03:11:24-07:00
by snibgo
%b and %[size] are strings, not numbers. I don't think IM can give you the size in bytes.
Re: how to get de-facto bits-per-pixel image property via identify
Posted: 2017-11-10T05:42:14-07:00
by AlexPUA
So, is there no solution inside IM at all ? Quite strange for such a powerful tool with all (trivial) data on the fingertips ...
Re: how to get de-facto bits-per-pixel image property via identify
Posted: 2017-11-10T13:00:21-07:00
by fmw42
You can test for KB or MB in the returned value and then multiply by 1000 or 1000000 and change KB or MB to B.
Re: how to get de-facto bits-per-pixel image property via identify
Posted: 2017-11-10T14:43:04-07:00
by snibgo
IM quite often doesn't provide facilities that are available elsewhere. IM is an
image processor, not a
file processor, so we often need to use script facilities to do what we want.
For example, in Windows CMD:
Code: Select all
for %F in (x*.jpg) do %IM%convert %F -format "%[fx:%~zF/w/h]" info:
Re: how to get de-facto bits-per-pixel image property via identify
Posted: 2017-11-10T15:33:54-07:00
by fmw42
What is your version of IM? On my 6.9.9.22 and 7.0.7.10 Q16 Mac OSX, I get B (bytes)
Code: Select all
convert barns_grand_tetons.jpg -format "%b\n" info:
836977B
Code: Select all
identify -format "%b\n" barns_grand_tetons.jpg
836977B
Code: Select all
identify -format "%[size]\n" barns_grans.jpg
836977B
It has been this way since IM 6.9.8.4
Re: how to get de-facto bits-per-pixel image property via identify
Posted: 2017-11-11T03:32:19-07:00
by AlexPUA
This code really works @ ImageMagick-7.0.3-Q16 and ImageMagick-7.0.7-Q16 (Windows-64)
Code: Select all
for %%F in (*.jpg) do magick convert "%%F" -format """%%f"" %%[fx:%%~zF/w/h]\n" info: >> files_info.txt
Re: how to get de-facto bits-per-pixel image property via identify
Posted: 2017-11-11T11:31:00-07:00
by fmw42
magick identify may be slightly faster than magick. You do not want to use magick convert. That points back to the IM 6 versions of convert. Just replace convert with magick. The other tools need to be prefaced with magick in IM 7
Re: how to get de-facto bits-per-pixel image property via identify
Posted: 2017-11-13T19:37:54-07:00
by fmw42
Note that you can use -precision to control whether you get B or KB or MB, but it round off the fractional part
Code: Select all
identify -format "%b\n" barns_grand_tetons.jpg
836977B
Code: Select all
convert -precision 3 barns_grand_tetons.jpg -format "%b\n" info:
837KB