PDA

View Full Version : Interrogating jpeg/jpg files



MWE
11-14-2007, 08:41 PM
this is not really an Excel question, but since what I want to do will be with Excel, I might as well start here ...

jpeg/jpg files contain lots of information about the image, e.g., date and time captured, type of camera, etc. I know how to fetch information about the file as a file object, e.g., date last saved, size, etc. But, how can one extract that "image" information from the jpeg file using VBA

malik641
11-15-2007, 07:25 AM
I've used Extended File Properties to handle CD files before (example below). Here is the article on it (http://www.microsoft.com/technet/scriptcenter/guide/sas_fil_lunl.mspx?mfr=true). I'm sure you can use it for your jpeg stuff.

Here's the code I used:
Option Explicit
Option Compare Text

Sub MusicFilesMove()
Dim Disc1 As String, Disc2 As String
Dim objShell As Object, objFolder As Object, FileName As Variant

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\...\My Music\Comedy\Dane Cook\")

Disc1 = objFolder.items.Item.path & "\" & "Retaliation Disc 1\"
Disc2 = objFolder.items.Item.path & "\" & "Retaliation Disc 2\"

For Each FileName In objFolder.items
Select Case objFolder.GetDetailsOf(FileName, 17)
Case "Retaliation (Disc 1)"
Name objFolder.items.Item.path & "\" & FileName As Disc1 & FileName

Case "Retaliation (Disc 2)"
Name objFolder.items.Item.path & "\" & FileName As Disc2 & FileName

End Select
Next FileName
End Sub
Good luck!

EDIT:
Looking at it further:
Camera Model Index = 24
Date Picture Taken Index = 25

rory
11-15-2007, 07:35 AM
JPG header structure information can be found here (http://groups.google.com/group/comp.lang.pascal.borland/msg/d4e229d903813bb8?hl=en&lr=&ie=UTF-8&oe=UTF-8) and there is a sample of how to get resolution and comment here (http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=vb&Number=342585&page=2&view=expanded&sb=5&o=0&fpart=). Should be adaptable to get whatever info is there...

MWE
11-15-2007, 03:55 PM
thanks, your reply was very helpful. I had the basic approach, I just did not let the index run far enough.

An dthanks for the JPEG Header link

MWE
11-15-2007, 05:55 PM
Based on some brute force fiddling, I think the following is true:

Index & Property
24 Camera Mfg/Model
25 Date/Time Taken (rounded to the nearest minute)
26 Image size in pixels (W x H)
27 Image width in pixels (also included in #26)
28 Image height in pixels (also included in #26)
31 Date/Time Taken including seconds (for JPG files from Nikon D80 but blank for Kodak C360)
40 ISO equivalent
41 focal length
42 Date/Time Taken including seconds
43 same as #24
44 f stop
45 speed
47 not sure; may be white balance
48 same as #26

Indices 29 to 30, 32 to 39, 46 and anything above 49 return nulls/blanks (at least for the jpg files sampled from two cameras). The duplication of some information suggests a two step process, i.e., image capture and digitization/compression into JPG format.

Any comfirming or contrasting info would be greatly appreciated.