Public Function resiseImage(ByVal fullPath As String, _
ByVal FinalSize As Integer, ByVal NewFullPath As String, _
Optional ByVal DeleteOriginal As Boolean = False) As String
Dim result As String = "Success"
Dim imagefolder As String = Path.GetPathRoot(fullPath)
Dim imagename As String = Path.GetFileName(fullPath)
Dim extension As String = Path.GetExtension(imagename)
Dim height As Integer
Dim width As Integer
Dim BiggerSide As String
Dim myratio As Decimal
Dim futureheight As Integer
Dim futurewidth As Integer
Dim Normal As System.Drawing.Image
Dim newimage As System.Drawing.Image
Normal = Normal.FromFile(fullPath)
height = Normal.Height
width = Normal.Width
If height > width Then
BiggerSide = "height"
myratio = FinalSize / width
futurewidth = myratio * width
Try
newimage = Normal.GetThumbnailImage(futurewidth, FinalSize, Nothing, New
IntPtr())
If File.Exists(imagefolder & imagename) Then File.Delete(imagefolder &
imagename)
newimage.Save(NewFullPath, System.Drawing.Imaging.ImageFormat.Jpeg)
Catch exp As Exception
result = "failed"
newimage.Dispose()
Throw exp
End Try
ElseIf width > height Then
BiggerSide = "width"
myratio = FinalSize / width
futureheight = myratio * height
Try
newimage = Normal.GetThumbnailImage(FinalSize, futureheight, Nothing, New
IntPtr())
If File.Exists(NewFullPath) Then File.Delete(imagefolder & imagename)
newimage.Save(NewFullPath, System.Drawing.Imaging.ImageFormat.Jpeg)
Catch exp As Exception
result = "failed"
newimage.Dispose()
Throw exp
End Try
Else
BiggerSide = "Same"
myratio = 1
Try
newimage = Normal.GetThumbnailImage(FinalSize, FinalSize, Nothing, New
IntPtr())
If File.Exists(NewFullPath) Then File.Delete(imagefolder & imagename)
newimage.Save(NewFullPath, System.Drawing.Imaging.ImageFormat.Jpeg)
Catch exp As Exception
newimage.Dispose()
result = "failed"
Throw exp
End Try
End If
Normal.Dispose()
newimage.Dispose()
If DeleteOriginal = True Then File.Delete(fullPath)
Return result
End Function
End Class