Google Answers Logo
View Question
 
Q: Creating a text file in Windows (ME) with image dimensions ( Answered 5 out of 5 stars,   2 Comments )
Question  
Subject: Creating a text file in Windows (ME) with image dimensions
Category: Computers > Operating Systems
Asked by: respree-ga
List Price: $2.00
Posted: 14 Jun 2003 10:15 PDT
Expires: 14 Jul 2003 10:15 PDT
Question ID: 217282
Greetings!

I would like to know how to create a plain text (.txt) file that will
give me the following information for graphical images contained in a
given directory.

Am running Windows ME.  Maybe a DOS command?  Don't know the /switch.
=(

Something like "dir *.jpg > output_filename.txt"

Output format should be like below (w/comma or tab delimiters)

[FILENAME],[IMAGE_WIDTH],[IMAGE_HEIGHT]

where [IMAGE_WIDTH] and [IMAGE_HEIGHT] denotes the number of pixels

I'm trying to determine if the images are horizontally or vertially
oriented (have about 100,000 image (.jpg) files).  Will figure that
part out in Access (once I get the dimensions).

Thanks for your help. =)
Answer  
Subject: Re: Creating a text file in Windows (ME) with image dimensions
Answered By: seizer-ga on 14 Jun 2003 12:36 PDT
Rated:5 out of 5 stars
 
Hi there respree!

I have a solution for you - it's a little inelegant, but it certainly
gets the job done!

First, you'll need the wonderful (and free) set of Imagemagick tools.
These truly are the batch image processor's friend, allowing you to do
almost anything to almost any image type. The Windows version is
available at the link below, and is approximately 2.3mb. Once you've
obtained these, unzip them to the default directory, so that they
appear in c:\VisualMagick.

ImageMagick tools for Windows:
http://www.dylanbeattie.net/magick/download/latest/ImageMagick.zip

Once you've done this, go to a DOS prompt, and type what appears
below, being sure to substitute the correct folder names where I've
written in CAPITALS. This solution does assume that all your JPEGs are
in one folder - if this is not the case, then let me know, and I'll
try and dream up a solution for that! Here's the command:

for %z in (c:\YOURJPEGFOLDER\*.jpg) do
c:\VisualMagick\bin\identify.exe -format "%f,%w,%h" %z >>
c:\WHEREVERYOUWANT\output_filename.txt

This should then run identify.exe on each of your files, and produce a
text file with the following format:

image1.jpg,640,480
image2.jpg,640,480
image3.jpg,1200,1600
image4.jpg,768,288
... and so on

Since you have around 100,000 images, I'd suggest letting it run for
half a minute, cancelling the operation with CTRL-C, and checking that
the output file is being created correctly - there's no point letting
it all run through, only to find you've missed a comma :-) Once you're
happy with how it's progressing, simply delete the output file, and
retype the command to restart the process.

I hope this sorts things out for you. If anything's unclear, or does
not work as expected, then please don't hesitate to use the request
clarification button before rating this answer.

All the best,

--seizer

Clarification of Answer by seizer-ga on 14 Jun 2003 18:22 PDT
The main command has been wrapped onto 3 lines - make sure to type it
in on just one!

--seizer

Request for Answer Clarification by respree-ga on 16 Jun 2003 14:32 PDT
Greetings seizer:

Many thanks for your response.  I just downloaded and installed the
program.  I'm wondering if you could direct me to the part of the site
(http://www.dylanbeattie.net) where I could get further documentation
on the command you provided or maybe you can see what I'm doing wrong.

I am getting the following error using the command below:

Input:
for %z in (c:\temppics\*.jpg) do
c:\VisualMagick\bin\identify.exe -format "%f,%w,%h" %z >>
c:\temppics1\dim.txt

Produces the following error on 'each' file not copied:
c:\>c:\visualmagick\bin\identify.exe -format "w,z IDENTIFY.EXE:
Missing an image file name.

I have verified that there are files in my source directory
(c:\temppics) and obviously each has a filename (with a .jpg
extension).

Can you assist further?  Out of curiosity, are you the author of the
program? Many thanks, once again.

Clarification of Answer by seizer-ga on 16 Jun 2003 17:08 PDT
Hello again respree!

I'm so sorry this isn't working as planned. The "for" command has been
built into command.com since MS-DOS 6, and has always worked as I used
it here, so I'm a little flummoxed. I am looking into it, so hang on
and hopefully we'll get there. In the meantime, please do check that
you typed it all on one line, exactly as I've written it in my answer!
You could also try putting in spaces in the format string, thus:

"%f, %w, %h" instead of "%f,%w,%h"

As for your other question: no, I am not the author of ImageMagick -
but thanks for the flattery! You can find out how to use identify.exe
in more depth here:

http://www.imagemagick.org/www/identify.html

Let me know if it suddenly works - otherwise I'll be looking into it
further.

All the best,

--seizer

Request for Answer Clarification by respree-ga on 16 Jun 2003 17:59 PDT
I'm sorry to put you through all this work for such a low fee.  I
actually thought the answer to my question was going to be a two
character answer (in the form of a DOS switch) that someone knew off
the top of their head.

To put your mind at ease, the error is not the result of a typo.  I
tried it about 10 times (thinking I could have made a typo, er..it is
a lot of typing) and got the same error message.

Thanks for your persistence.

Clarification of Answer by seizer-ga on 16 Jun 2003 18:49 PDT
A couple of my (rather brighter) fellow researchers have also come up
blank on this one too, I'm afraid. I'm sorry to accuse you of lax
typing - but if one doesn't ask....

The command I offered (which works so admirably on my system, and so
dismally on yours) essentially runs IDENTIFY.EXE on each jpeg in a
particular folder. Since the built-in command "FOR" seems not to
function as expected, I would be happy to write you a program as an
alternative. This would, of course, entail you running an EXE file
created by myself, so if you feel uncomfortable with this option, and
I have no further alternatives, I will be more than happy to request
my answer's removal.

Let me know what you think!

All the best,

--seizer

Request for Answer Clarification by respree-ga on 16 Jun 2003 20:12 PDT
No need to apologize.  While I can type with great speed, I cannot say
I can type with great accuracy. =) (which is the reason I tried it 10
times).

Thanks for your generous offer, but lets hold off for now.  No point
reinventing the wheel.  I've e-mailed imagemagick to see if they would
be kind enough to assist.

BTW, while not my first choice, do you know if my request can done on
Linux instead (without writing a program) with a simple command (i.e.
height, width capability built into OS)?  I'll understand if that is
not your field of expertise, though.

Clarification of Answer by seizer-ga on 17 Jun 2003 03:17 PDT
My continuing apologies for the mess. I believe the bug must be with
Windows ME, as I successfully tried this under Windows XP and Windows
98 (and recall using the command under DOS 6).

However: colour me extremely foolish, because I've just noticed that
ImageMagick supports wildcards in the filename options. You may well
just be able to type the following command, rather than relying on the
"FOR" iterator:

c:\VisualMagick\bin\identify.exe -format "%f,%w,%h" c:\temppics\*.jpg
> dim.txt

If this works, hurrah, and shame on me. If not, you could look instead
at jhead, available at the following link, which reads JPEG headers
(thus the name). The command line option "-c" shows concise output,
and removes the need for the percentage signs which seem to be the
problem:

http://www.sentex.net/~mwandel/jhead/

Both ImageMagick and jhead are available for linux too. The reason
that no such functionality is built into most operating systems (apart
from image previewing in some versions of Windows) is that image
formats are a moving target, and new formats arrive constantly
(JPEG2000 is nearly here, and PNG has already made a recent impact).
Thus, these things are better left to third party developers.

Anyway, let me know if either of the suggestions work!

All the best,

--seizer

Request for Answer Clarification by respree-ga on 17 Jun 2003 10:56 PDT
I admire your persistence.  Thanks, once again.

c:\VisualMagick\bin\identify.exe -format "%f,%w,%h" c:\temppics\*.jpg
> dim.txt

Good news.  The command above produced no errors.
Bad news.  The dim.txt file it created contained no data (odd, huh?)
 
Have downloaded this file.
http://www.sentex.net/~mwandel/jhead/

Would you be so kind as to tell me what to type in using the jhead
command. Visited the site, but its awfully cryptic and I couldn't
understand the example provided (or at least how to apply it to my
particular case).

P.S. I haven't heard back from imagemagick.  I suspect they won't drop
everything they're doing just to help me.  Could be a while (or
never).  It seems like if the question is accepted, it gets posted
onto a bulletin board for others to answer.  But the problem is I
can't get into the bulletin board (password required).

Been fooling around with it for an hour, but still no luck. =(

Thanks again.

Clarification of Answer by seizer-ga on 17 Jun 2003 13:44 PDT
Hello again!

Does the command work if you do not include the "> dim.txt" portion
(thus echoing all output to the screen)? Does it "chug" the hard disk
for a while, before returning you to a prompt?

What happens if you run that command on a directory which contains
only a few pictures, rather than the full 100,000 of them?

The jhead command syntax is very simple:

jhead -c *.jpg

Unfortunately, the output isn't optimal: it looks like this:

"image1.jpg" 640x480 
"image2.jpg" 640x480 
"image3.jpg" 1200x1600 
"image4.jpg" 768x288 

Hopefully, we can make some progress - this bug is an odd one, but I
don't have access to a Windows ME computer to determine whether it's
global for all copies of the OS, or just specific to your computer's
configuration!

All the best,

--seizer

Request for Answer Clarification by respree-ga on 17 Jun 2003 14:22 PDT
Hi seizer:

[Does the command work if you do not include the "> dim.txt" portion
(thus echoing all output to the screen)? Does it "chug" the hard disk
for a while, before returning you to a prompt?]

This is rather interesting (actually, to be more to the point...weird)

This command:
c:\>c:\visualmagick\bin\identify.exe -format "%f,%h,%w"
c:\temppics\*.jpg

Produces this result (six files in the test directory)
h,108
h,108
h,108
h,108
h,87
h,87

(Comment:  Seems to pick up the height, but not the filename or width,
odd huh?)

However, this command (with the > c:\temppics1\dim.txt):
c:\>c:\visualmagick\bin\identify.exe -format "%f,%h,%w"
c:\temppics\*.jpg > c:\temppics1\dim.txt

Produces:
A text file with nothing in it...

GOOD NEWS.  I tried the jhead command and it works.  Although the
format is not exactly what I had hoped for, I'll peel the height and
width fields from the single field I need when I bring it into access.

dim.txt =

"c:\temppics\a.jpg" 108x38
"c:\temppics\b.jpg" 108x38
"c:\temppics\c.jpg" 108x37
"c:\temppics\d.jpg" 108x37
"c:\temppics\e.jpg" 87x108
"c:\temppics\f.jpg" 87x108

Thank you so much for all your hard work.

Clarification of Answer by seizer-ga on 17 Jun 2003 15:31 PDT
Thank you so much for the generous rating and tip. It's much
appreciated (though perhaps not deserved!)

May I briefly offer a last comment - a post mortem, if you will. It
would seem that for some reason, the %f part of the command line is
being rejected by command.com. I wouldn't venture an explanation right
now, but I certainly will keep my eyes open for anything similar. It's
just unfortunate (though not unwise) that ImageMagick chose to use %f
for the filename portion of their formatting string.

Anyway, enough technical rambling: I'm glad we finally got you up and
running!

All the best, 

--seizer
respree-ga rated this answer:5 out of 5 stars and gave an additional tip of: $15.00
Absolutely fantastic service. Highly recommended. I had a seemlingly
simple question that turned into somewhat of a nightmare, full of
unexpected complexities.  Seizer was so persistent in helping me find
the answer to my question - all without the promise of more money.  A
true professional in every sense of the word.

Comments  
Subject: Re: Creating a text file in Windows (ME) with image dimensions
From: missy-ga on 14 Jun 2003 10:25 PDT
 
Hi Garrick!

Nice to see you back!

If your only concern is to determine image orientation, perhaps you
might try setting your folder view to "Thumbnails"?  Open the folder
containing your images, then in the menu bar, select View, then
Thumbnails.  Shazaam!  Quick visual check!

(Also, if you store the images directly in the My Pictures folder
(located in My Documents), clicking the image will give you the size
in KB and the dimensions in pixels in the sidebar.)

I realize this isn't practical for the large number of images you
have, but perhaps it will help a bit while you're waiting for a
Researcher with some DOS aptitude!

--Missy
Subject: Re: Creating a text file in Windows (ME) with image dimensions
From: respree-ga on 14 Jun 2003 10:35 PDT
 
Hi Missy! Good to hear from you.

Thanks for your suggestion.

Unfortunately, a visual inspection would take me about a hundred years
due to the sheer volume of data I'm dealing with.  I actually have a
database with the dimensions, but I'm trying to determine the
integrity of the data I have (i.e. which ones are wrong [height and
width flip-flopped]).

Hope all is well.  Take care.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy