Summation of width and height to be displayed as prefix to photo name

Started by aniecki, October 19, 2020, 12:31:13 PM

Previous topic - Next topic

aniecki

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.

StarGeek

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.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

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
...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 ($).

aniecki

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!



StarGeek

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

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.  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
...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 ($).

Phil Harvey

...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 ($).

aniecki

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!

Phil Harvey

...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 ($).

aniecki

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.

Phil Harvey

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

- 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 ($).

aniecki

Thanks Phil, yes after giving me lead I even figured it out.