How to get and write the dimensions of images on hard drive into an Access table

clock1
clock1 used Ask the Experts™
on
Have 20,000 images in C:\pictures that contains 10GB of images of various sizes.
Have a table that contains a field named "Location" that lists path of each image.
Have created a field in same table named "Dimension".
Want to determine the aspect ratio of each image based on width x height.
How can I get and store in same table the dimension of each image without crashing Access?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2014

Commented:
Start here
http://www.experts-exchange.com/articles/13779/More-Fun-with-Really-Large-High-Fidelity-Images-in-Access-Reports.html

It's fairly straight-forward
Set a reference to WIA
'need a reference to MS Windows Image Acquisition 2.0 library

Dim rs as recordset
Set rs = CurrentDb.Openrecordset("Select * from Location;")

Create an Image object
Dim Img As WIA.ImageFile

Dim ThePath as String
ThePath= rs!ThePath

do unitl rs.EOF
     'Set it to a filepath
      Img.LoadFile ThePath

    With rs
         .Edit
         !Dimension = Img.Height/Img.Width
         .Update
    End with
    Set Img = Nothing
    rs.movenext
Loop

Make sense?

Author

Commented:
Does rs!ThePath take the entire path listed in location?
Most Valuable Expert 2014
Commented:
I am guessing as to what the fields in your table Location are named
Img.LoadFile requires a fully qualified path string i.e.

"c:\Somefolder\SomeSubFolder\SomeFile.jpg"

'need a reference to MS Windows Image Acquisition 2.0 library

 Dim rs as recordset
 Set rs = CurrentDb.Openrecordset("Select * from Location;")

 Create an Image object
 Dim Img As WIA.ImageFile
 Dim ThePath as String

Do Until rs.EOF
       ThePath= rs!ThePath
      'Set it to a filepath
       Img.LoadFile ThePath

     With rs
          .Edit
          !Dimension = Img.Height/Img.Width
          .Update
     End with
     Set Img = Nothing
     rs.movenext
 Loop

Open in new window

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Yes, contains legitimate file path.  I'll give it a try.
Most Valuable Expert 2014

Commented:
Make sure you set the Reference!
The article has a working sample at the end of it.

Author

Commented:
As I try this and read article, notice that author states cannot get 1000 images to work.  As stated in onset, I have 20,000 images.  But continuing to work.
Most Valuable Expert 2014

Commented:
I am the author.
If you want to make 1000's PRINT on a report, well, yeah, that doesn't fly.
Processing 10's of thousands for length and width?  Piffle.

Author

Commented:
How do I earn Piffle when  I stated 20,000 images at beginning.  Sorry, no go solution.
Most Valuable Expert 2014

Commented:
Sigh. YOU don't earn piffle.  The task at hand does :)

Getting a thousand jpgs to print on a report is VERY difficult for Access.
Getting Access to process 20K images for which you have fully qualified paths is child's-play for Access.
It'll be resource-intensive and take a bit, but eminently doable.
About 15-20 minutes or so for 20K files

Hence, piffle.

Sample attached.
This one takes 20K records from one table, finds if they exists and adds results to a second table.
Not quite what you are doing, but I am not altering production data for a sample!  You don't have my files, but the code and tables are tested and work.
piffle.mdb

Author

Commented:
Opened mdb.  Clicked process. Expected to see dimension added to picture table.  What have I overlooked?

Author

Commented:
Disregard last comment from me.  Realize that images are on your location and no error checking in place.
Most Valuable Expert 2014

Commented:
The error checking is in place -- but since fs.FileExists(ThePath) will return false in every case on your machine, that's the branch that runs, and no records get written.
Replace the data in tblPictures with valid data of your own and you are in business.

Author

Commented:
Error checking as in MsgBox stating done appeared without error.  I'm good to try again.
Most Valuable Expert 2014

Commented:
Going home for the weekend!
Hopefully, the code made sense to you.

Nick67

Author

Commented:
Made sense.  Thanks, points are yours!

Author

Commented:
Made sense.  Thanks, points are yours!
Most Valuable Expert 2014

Commented:
You're welcome!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial