Main Menu

Image File Size

Started by brownbeardad, February 08, 2019, 06:03:32 PM

Previous topic - Next topic

brownbeardad

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.

Stephen Marsh

#1
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

StarGeek

The only problem with using the -n (printConv) option 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 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)',
},
#------------------------------------------------------------------------------
},
);

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

brownbeardad

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.

brownbeardad

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

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).