Sub CreateWebPreview(ImageFile, imgRootPath)
    Dim Doc, PScale, xSize, ySize, dStrm, sMin, sMax

' Open the image
    Set Doc = CreateObject("MaxIm.Document")
    Doc.OpenFile ImageFile

' Bin 2x2 as long as image is >=4x the preview size (binning doesn't blur hot pixels, and is far faster than the Resize function)
    Do While Doc.XSize >= 4096
        Doc.Bin(2)
    Loop

' Filter hot pixels prior to resize
    Doc.KernelFilter 5, 20

' Resize image to max 1024 pixels wide
    PScale = Fix(Doc.XSize / 1024) + 1
    If Doc.XSize >= 1024 And CInt(Doc.XSize / 1024) = Doc.XSize / 1024 Then PScale = PScale - 1 ' Catch edge condition
    If PScale < 1 Then PScale = 1
    xSize = Fix(Doc.XSize / PScale) ' For the dims file
    ySize = Fix(Doc.YSize / PScale)
    Doc.Resize xSize, ySize

' Beautify preview image 
    Doc.DDP 0, true, true, 0, 0, 100 ' (0=FFT-lowpass, AutoBgd, AutoMidLevel, Bgd, MidLevel, Cutoff)  ' Denny
    Doc.RemoveGradient

    Doc.SaveFile imgRootPath + LSTPNG_FILE, 7, True, 0 ' Scaled, 8-bits/pix, PNG
    On Error Resume Next
    Util.WaitForMilliseconds 500    ' [BUG/WORKAROUND] See 25-Oct-2004 edit track

' Save dimensions of preview
    Set dStrm = FSO.CreateTextFile(imgRootPath + LSTDIM_FILE, True) ' Make new preview dimensions file
    dStrm.WriteLine xSize           ' Dims one per line
    dStrm.WriteLine ySize
    dStrm.Close

' Create thumbnail at 128 pixel wide
    PScale = Fix(Doc.XSize / 128) + 1
    If Doc.XSize >= 128 And CInt(Doc.XSize / 128) = Doc.XSize / 128 Then PScale = PScale - 1   ' Catch edge condition
    If PScale < 1 Then PScale = 1
    Doc.Resize (Doc.XSize / PScale), (Doc.YSize / PScale)

    Doc.SaveFile imgRootPath + THUMB_FILE, 7, True, 0 ' Scaled, 8-bits/pix, PNG
    On Error Resume Next
    Doc.Close                       ' Close for MaxIm V4 only
    On Error Goto 0
    Util.WaitForMilliseconds 500    ' [BUG/WORKAROUND] See 25-Oct-2004 edit track
End Sub
