ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Get Dimensions of Image File Outside Excel (https://www.excelbanter.com/excel-programming/409866-get-dimensions-image-file-outside-excel.html)

Lazzaroni

Get Dimensions of Image File Outside Excel
 
Does anyone know how to retrieve the image size (width and height) in pixels
of an image that is not inside a spreadsheet?

When I hover my mouse pointer over images on my desktop the image size pops
up in Windows Vista, but I don't know how to retrieve this particular
attribute of the file from inside Excel 2007.

Thank you.

Steve Yandl

Get Dimensions of Image File Outside Excel
 
If you check out the link below, I have a script that uses the
"Shell.Application" object to retrieve the dimensions of various types of
picture files as part of the process. You will have to wade through the
other stuff it's doing but it should be easy enough to incorporate. The key
is going to be that you will first need to retrieve the complete file name
including the path (I use WScript arguments as the script is designed so the
user can drag the picture into the file and have it do its thing). I'm
still running WinXP and Excel 2003 so I won't presume to be able to share
exactly how you will need to approach file name retrieval.
http://www.microsoft.com/technet/scr.../cscme009.mspx


Steve Yandl



"Lazzaroni" wrote in message
...
Does anyone know how to retrieve the image size (width and height) in
pixels
of an image that is not inside a spreadsheet?

When I hover my mouse pointer over images on my desktop the image size
pops
up in Windows Vista, but I don't know how to retrieve this particular
attribute of the file from inside Excel 2007.

Thank you.




Lazzaroni

Get Dimensions of Image File Outside Excel
 
Steve:

That's what I was looking for. The FileSystemObject and the GetDetailsOf
method.

I had to change the GetDetailsOf method constant from 26 to 31 to return the
image dimensions. 26 returned nothing. I checked the FSO documentation but
could not find anything on this. Perhaps it is because I am using Windows
Vista.

Using GetDetailsOf constant 31 returns the image dimensions, but enclosed in
mystery characters that appear as question marks on my computer. That's the
reason for the additional string manipulation.

Perhaps someone can explain the change in the constant, or improve upon my
code.

Thank you for your help.

Function GetImageDimensions(ByVal strPath As String, Optional ByRef lngWidth
As Long, Optional ByRef lngHeight As Long) As Boolean

Dim objFSO As New FileSystemObject
Dim objShell As Object
Dim objFolder As Object
Dim varFileName As Variant
Dim strDimensions() As String

ReDim strDimensions(0)

Const filePropName = 0
Const filePropType = 2
Const filePropDimensions = 31 '26?

If objFSO.FileExists(strPath) Then

GetImageDimensions = True

Set objShell = CreateObject("Shell.Application")
Set objFolder =
objShell.Namespace(objFSO.GetParentFolderName(strP ath))

For Each varFileName In objFolder.Items

If objFolder.GetDetailsOf(varFileName, filePropName) =
objFSO.GetFileName(strPath) Then
strDimensions(0) = objFolder.GetDetailsOf(varFileName,
filePropDimensions)
If InStr(strDimensions(0), " x ") 0 Then
strDimensions = Split(strDimensions(0), "x")
lngWidth = CLng(Mid(Trim(strDimensions(0)), 2))
lngHeight = CLng(Mid(Trim(strDimensions(1)), 1,
Len(Trim(strDimensions(1))) - 1))
Exit For
Debug.Print lngWidth
Debug.Print lngHeight
End If
End If
Next

End If

Set objFSO = Nothing
Set objFolder = Nothing
Set objShell = Nothing

End Function

Steve Yandl

Get Dimensions of Image File Outside Excel
 
The article in this link is what I used to get started. I suspect that your
issue is rooted in changes made in Vista. Perhaps something in the article
will help you search for updated information for a Vista system.

http://www.microsoft.com/technet/scr....mspx?mfr=true

Steve


"Lazzaroni" wrote in message
...
Steve:

That's what I was looking for. The FileSystemObject and the GetDetailsOf
method.

I had to change the GetDetailsOf method constant from 26 to 31 to return
the
image dimensions. 26 returned nothing. I checked the FSO documentation but
could not find anything on this. Perhaps it is because I am using Windows
Vista.

Using GetDetailsOf constant 31 returns the image dimensions, but enclosed
in
mystery characters that appear as question marks on my computer. That's
the
reason for the additional string manipulation.

Perhaps someone can explain the change in the constant, or improve upon my
code.

Thank you for your help.

Function GetImageDimensions(ByVal strPath As String, Optional ByRef
lngWidth
As Long, Optional ByRef lngHeight As Long) As Boolean

Dim objFSO As New FileSystemObject
Dim objShell As Object
Dim objFolder As Object
Dim varFileName As Variant
Dim strDimensions() As String

ReDim strDimensions(0)

Const filePropName = 0
Const filePropType = 2
Const filePropDimensions = 31 '26?

If objFSO.FileExists(strPath) Then

GetImageDimensions = True

Set objShell = CreateObject("Shell.Application")
Set objFolder =
objShell.Namespace(objFSO.GetParentFolderName(strP ath))

For Each varFileName In objFolder.Items

If objFolder.GetDetailsOf(varFileName, filePropName) =
objFSO.GetFileName(strPath) Then
strDimensions(0) = objFolder.GetDetailsOf(varFileName,
filePropDimensions)
If InStr(strDimensions(0), " x ") 0 Then
strDimensions = Split(strDimensions(0), "x")
lngWidth = CLng(Mid(Trim(strDimensions(0)), 2))
lngHeight = CLng(Mid(Trim(strDimensions(1)), 1,
Len(Trim(strDimensions(1))) - 1))
Exit For
Debug.Print lngWidth
Debug.Print lngHeight
End If
End If
Next

End If

Set objFSO = Nothing
Set objFolder = Nothing
Set objShell = Nothing

End Function





All times are GMT +1. The time now is 02:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com