ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: aniecki on October 19, 2020, 12:31:13 PM

Title: Summation of width and height to be displayed as prefix to photo name
Post by: aniecki on October 19, 2020, 12:31:13 PM
Is there an easy way to do this - by renaming a set of photos to contain a sum of the two?
I know that width and height can be rather easily displayed in a renamed photo, but a  summation (say 5 digit format) of these two values?  Thanks.
Title: Re: Summation of width and height to be displayed as prefix to photo name
Post by: StarGeek on October 19, 2020, 12:43:37 PM
Try
exiftool "-Filename<${Megapixels#;$_*=1000000}%f.%e" /path/to/files/

More details would be needed to limit it to five digits, as any image over 316x316 would exceed five digits.
Title: Re: Summation of width and height to be displayed as prefix to photo name
Post by: Phil Harvey on October 19, 2020, 01:21:04 PM
If you really want the sum and not the product, you could do this:

exiftool "-testname<%f-${imagesize;tr/x/+/;$_=sprintf '%.5d',eval}.%e" DIR

If this gives you the names that you want, then replace "testname" with "filename" to do the actual renaming. With this, a 2688x2016 image named "phil.jpg" would be renamed to "phil-04704.jpg".

- Phil
Title: Re: Summation of width and height to be displayed as prefix to photo name
Post by: aniecki on October 19, 2020, 02:02:07 PM
Thanks Gents.
I have modified to fit Linux
exiftool '-testname<%f-${imagesize;tr/x/+/;$_=sprintf "%.5d",eval}.%e' .

Ok, now when I am done.
How to come to this result, where to study to understand it? Do I have to study Perl?

Cheers!


Title: Re: Summation of width and height to be displayed as prefix to photo name
Post by: StarGeek on October 19, 2020, 02:11:41 PM
Quote from: Phil Harvey on October 19, 2020, 01:21:04 PM
If you really want the sum and not the product,

Ooops, I should read more closely.
Title: Re: Summation of width and height to be displayed as prefix to photo name
Post by: Phil Harvey on October 19, 2020, 02:12:54 PM
Quote from: aniecki on October 19, 2020, 02:02:07 PM
How to come to this result, where to study to understand it? Do I have to study Perl?

The basics of file renaming are explained here (https://exiftool.org/filename.html).  The advanced formatting feature is explained in the -tagsfromfile section of the documentation, but the expressions (ie. tr/x/+/;$_=sprintf "%.5d",eval) are pure Perl and require a knowledge of the language.

- Phil
Title: Re: Summation of width and height to be displayed as prefix to photo name
Post by: Phil Harvey on October 19, 2020, 02:13:36 PM
Quote from: StarGeek on October 19, 2020, 02:11:41 PM
Ooops, I should read more closely.

...for once I'm the one that read things correctly. :P

- Phil
Title: Re: Summation of width and height to be displayed as prefix to photo name
Post by: aniecki on October 19, 2020, 04:20:08 PM
The product is also an interesting example here. Perhaps there is way to correct it slightly to change the format,
as given
'./CO-0282x0225-0005.jpg --> './63450CO-0282x0225-0005.jpg'

to (with leading zero)
'./CO-0282x0225-0005.jpg --> './063450CO-0282x0225-0005.jpg'

So even the low pixel photos will be prefixed with the same length string?

Thanks!
Title: Re: Summation of width and height to be displayed as prefix to photo name
Post by: Phil Harvey on October 19, 2020, 07:01:34 PM
Just change %.5d to %.6d in the sprintf format string.

- Phil
Title: Re: Summation of width and height to be displayed as prefix to photo name
Post by: aniecki on October 20, 2020, 01:05:26 AM
For the sum, yes, yet the first example given was for product, so the problem with this command:

exiftool "-Filename<${Megapixels#;$_*=1000000}%f.%e" /path/to/files/

is that that here is not a format for the string.

282x225 eq 63450 is a 5 digit number, and we want it to be 6 digit (with leading zero).

Thanks.
Title: Re: Summation of width and height to be displayed as prefix to photo name
Post by: Phil Harvey on October 20, 2020, 06:35:31 AM
exiftool "-Filename<${Megapixels#;$_=sprintf '%.6d', $_*1000000}%f.%e" /path/to/files/

- Phil
Title: Re: Summation of width and height to be displayed as prefix to photo name
Post by: aniecki on October 21, 2020, 03:16:06 AM
Thanks Phil, yes after giving me lead I even figured it out.