How to determine the image size of a tiff file?

I have a vbscript script and I need to chew on a .tif file directory. For each file, I need to determine if the file is proportional as a landscape or portrait. Basically, I need to be able to get image sizes for each file. So, I saw some examples of people reading file header files to extract this information from jpg or bmp files. Has anyone done the same to extract sizes for a tiff file?

+3
source share
2 answers

In VBScript, you can define image sizes in two ways:

  • Using the WIA Automation Library ( download link , MSDN Documentation , excellent Hey article, Scripitng Guy!. After registering the wiaaut.dll library, you can use the following simple code:

    Set oImage = CreateObject("WIA.ImageFile")
    oImage.LoadFile "C:\Images\MyImage.tif"
    
    WScript.Echo "Width: "  & oImage.Width & vbNewLine & _
                 "Height: " & oImage.Height
    


  • Using the method GetDetailsOfto read the corresponding advanced file properties. This is a native Windows scripting method, so external libraries are not required; but the code is longer:

    Const DIMENSIONS = 31
    CONST WIDTH  = 162
    CONST HEIGTH = 164
    
    Set oShell  = CreateObject ("Shell.Application")
    Set oFolder = oShell.Namespace ("C:\Images")
    Set oFile   = oFolder.ParseName("MyImage.tif")
    
    strDimensions = oFolder.GetDetailsOf(oFile, DIMENSIONS)    
    strWidth  = oFolder.GetDetailsOf(oFile, WIDTH)
    strHeigth = oFolder.GetDetailsOf(oFile, HEIGTH)
    
    WScript.Echo "Dimensions: " & strDimensions & vbNewLine & _
                 "Width: "      & strWidth      & vbNewLine & _
                 "Height: "     & strHeigth
    

    This script outputs something like:

    Dimensions: 2464 x 3248
    Width: 2464 pixels
    Height: 3248 pixels.

    therefore, if you need prime numbers, you will have to extract them from the returned strings.

    - ( script) Windows, . script Windows 7, Windows , script Windows, , . .

+9

Atalasoft DotImage Photo ! .NET, Regasm Magic, . vb.net VBScript, .

, .

Public Function GetHeight(path As String) As Integer

    Using stm As New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)
        Dim decoder As New TiffDecoder()
        If Not decoder.IsValidFormat(stm) Then
            Throw New Exception("not a TIFF")
        End If
        Dim image As AtalaImage = decoder.Read(stm, Nothing)
        Return image.Height
            ' Return image.Width --- To return the Width.

    End Using
End Function
+1

Source: https://habr.com/ru/post/1789313/


All Articles