ExifTool Forum

ExifTool => Newbies => Topic started by: brownbeardad on February 08, 2019, 06:03:32 PM

Title: Image File Size
Post by: brownbeardad on February 08, 2019, 06:03:32 PM
I am very new to exiftool. I am going through exif data for more than 27,000 images. I notice that image file size tag is sometimes in KB and sometimes in GB. I have spent the last two days looking for information to change how Perl (or exiftool.pl) writes this tag. I have searched FAQ's and searched forum discussions. I prefer the dimension of this tag be constant and in KB's. I did find reference to making custom column headers but not changing the dimension of the image file size. I am using this command "exiftool.pl -csv -r pictures > out.txt". I am not certain whether file size is direct info or calculated. I will appreciate assistance to change how this metadata is written.
Title: Re: Image File Size
Post by: Stephen Marsh on February 08, 2019, 07:15:04 PM
You could try using the -n (--printConv) argument to disable the output conversion:

exiftool -n -filesize file.jpg
File Size  : 7064684


vs.

exiftool -filesize file.jpg
File Size : 6.7 MB



Or if you don't wish to disable the print conversion of all tags, you can use the # symbol suffix to disable specific tag conversion, such as:

exiftool -filesize# -filesize file.jpg
File Size : 7064684
File Size : 6.7 MB



The Mac Finder reports: 7,064,684 bytes (7.4 MB on disk)
Windows reports: 6.73 MB (7,064,684 bytes)

You may also wish to look into the -p (-printFormat) argument as well:

https://exiftool.org/exiftool_pod.html
Title: Re: Image File Size
Post by: StarGeek on February 09, 2019, 01:03:14 PM
The only problem with using the -n (printConv) option (https://exiftool.org/exiftool_pod.html#n---printConv) is that it will affect all tags, which may not be what brownbeardad wants, since that is what the example shows.

Since this has come up before, I threw together a quick and dirty config file that will return filesize in kB.  (Side question, is that supposed to be kB or KB?  I can never keep it straight.)

It can be used directly with the -Config option (https://exiftool.org/exiftool_pod.html#config-CFGFILE) or it can be added to the .exiftool_config file.

Any comments?  Should the decimals be round off?

Example output:
C:\>exiftool -config FilesizeTags.config -g1 -a -s -FileSize -FilesizeKB -FilesizeKB# y:\!temp\Test4.jpg Y:\!temp\test_drive.MP4
======== y:/!temp/Test4.jpg
---- System ----
FileSize                        : 549 kB
---- Composite ----
FilesizeKB                      : 548.639 kB
FilesizeKB                      : 548.639
======== Y:/!temp/test_drive.MP4
---- System ----
FileSize                        : 83 MB
---- Composite ----
FilesizeKB                      : 84,921.268 kB
FilesizeKB                      : 84921.268
    2 image files read



# commify taken from https://www.perlmonks.org/?node_id=653
sub commify {
       my $input = shift;
        $input = reverse $input;
        $input =~ s<(\d\d\d)(?=\d)(?!\d*\.)><$1,>g;
        return reverse($input).' kB';
}

%Image::ExifTool::UserDefined = (
'Image::ExifTool::Composite' => {
#------------------------------------------------------------------------------
FilesizeKB => {
Require => 'FileSize',
PrintConv => 'commify( $val)',
ValueConv =>  'sprintf("%.3f",$val/1024)',
},
#------------------------------------------------------------------------------
},
);

Title: Re: Image File Size
Post by: brownbeardad on February 10, 2019, 10:39:47 AM
Thanks for the quick responses and relevant options. I will study your responses, still new enough to need some time to process. Then try a test case to make sure I am using the proper syntax. Thanks again, I'll post later when successful.
Title: Re: Image File Size
Post by: brownbeardad on February 10, 2019, 01:34:31 PM
After completing a few examples, I am satisfied with the following command: exiftool.pl -filesize# -filesize -csv -r pictures > out.txt. This command does require the creation of a column next to filesize# and dividing by 1024 to convert bytes to KB. Not much work after importing text file to Excel and considering the number of image files and alternative.

I completed examples for the config file changes, but was getting a message "config file not found". Certain this is because I did not edit the exigtool_config file. I was not certain how the change would work with the Perl distributable; and with my limited understanding, not comfortable enough at this time to take this change on.

Thanks for the help Stephen and StarGeek. The exiftool and your help has saved me a significant amount of time,. Time that would have made this task not possible. Do the forum have a reputation feedback system? And how do I close this post as solved?

Brownbeardad
Title: Re: Image File Size
Post by: Phil Harvey on February 10, 2019, 01:40:37 PM
Consider it closed then.  There is no reputation system and no real way to mark a thread as solved (other than changing the subject).

- Phil