Saving all dimension information to a file

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Loikkanen
Posts: 2
Joined: 2016-01-06T02:59:04-07:00
Authentication code: 1151

Saving all dimension information to a file

Post by Loikkanen »

I want save all information of the dimensions of all jpg's in a directory (including sub-directories).

This seem to work: FOR /R %f IN (*.jpg) DO identify "%f" -size 1920x1080

using standard output like this:
FOR /R %f IN (*.jpg) DO identify "%f" -size 1920x1080 > \dimensions.txt
creates the file dimensions.txt each time as a new file.

and this creates a text file for each jpg, but the files are all across the sub-directories:
FOR /R %f IN (*.jpg) DO identify "%f" -size 1920x1080 > %f.txt

Is there a parameter for sub-directories for identify?
Or any other suggestions?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Saving all dimension information to a file

Post by fmw42 »

You will have to traverse your directory structure in your looping mechanism
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Saving all dimension information to a file

Post by GeeMack »

Loikkanen wrote:I want save all information of the dimensions of all jpg's in a directory (including sub-directories).

This seem to work: FOR /R %f IN (*.jpg) DO identify "%f" -size 1920x1080

using standard output like this:
FOR /R %f IN (*.jpg) DO identify "%f" -size 1920x1080 > \dimensions.txt
creates the file dimensions.txt each time as a new file.
On Windows 7 64, and using IM7, this will make a single file containing all the file names and dimensions for all the JPGs in the directory "C:\your_directory\" and all its subdirectories.

Code: Select all

for /R C:\your_directory\ %I in ( *.jpg ) do identify -format "%f %wx%h\n" "%I" >> \dimensions.txt
It should work the same way on almost any version of Windows and with at least versions 6 and 7 of ImageMagick.

If you want the image file names in your output to include the full path, use "%i" instead of "%f" in your "identify" format string.

The drive and path you're searching needs to be in your "for" command right after the "/R" flag.

The output file, "dimensions.txt", will be created (or appended) in the root of the drive you run the command from, like "C:\dimensions.txt". You can, of course, specify any other location and file name.

You need to use the double redirect ">>" in order to append each new line of information to the file. Using just one ">" like you had in your command will overwrite the file each time the loop runs and leave only the last line of data in the file.

Make sure you clear that data file or delete it before you run the command again if you don't want to continue adding to it.

If you put the commands in a batch file, use two percent signs "%%" everywhere you use one "%" on the command line.
Loikkanen
Posts: 2
Joined: 2016-01-06T02:59:04-07:00
Authentication code: 1151

Re: Saving all dimension information to a file

Post by Loikkanen »

Thank you. That worked.
It seems that you can omit the directory, so you can copy the cmd to another directory and use it as it is.

Code: Select all

for /R %%I in ( *.jpg ) do identify -format "%%i %%wx%%h\n" "%%I" >> \dimensions.txt
Post Reply