Page 1 of 1
add image height and width to file name

Posted:
Fri Dec 08, 2017 10:02 am
by jay gray
On Windows 10 and for a PNG or JPG/JPEG, is it possible to extract the height and width dimensions from file properties and append those properties to the file name? For example:
for file.png with Details (from Win10 Properties)
Dimensions 27 x 18
Width 27 pixels
Height 18 pixels
replace file.png with:
file_w27_h18.png
or
file 27 x 18.png (taking the values from the Dimensions field - I can later replaces spaces with a character separator like underscore)
/jay gray
Re: add image height and width

Posted:
Fri Aug 14, 2020 5:37 pm
by JohnDepot
Same problem, looking to add a prefix of "000x000' with Height and Width of a folder of BMP files.
Re: add image height and width

Posted:
Fri Aug 14, 2020 8:03 pm
by JohnDepot
Found a solution;
Using Javascript Renaming (12) to append the width and height of the image onto the end of the file name.
Ex. Image.bmp -> Image_100x100.bmp
var width = filePropertyNum('Width');
var height = filePropertyNum('Height');
newName = name + '_[' + width + 'x' + height +']'
I will keep playing with it because i want to make sure there is a 3 digit buffer, so that 80x93 will be 080x093, and post an update when I get it!
Re: add image height and width

Posted:
Fri Aug 14, 2020 8:09 pm
by JohnDepot
var w = filePropertyNum('Width');
var h = filePropertyNum('Height');
function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
var width = pad(w,3);
var height = pad(h,3);
newName = name + '_-_[' + width + 'x' + height +']'