Hate to be paranoid, but....
I wrote a function that takes the height and width of a full size, uploaded image and returns - allegedly, It seems to anyway - new dimensions with the aspect ratio preserved.
My function seems awkward. Could anyone suggest a better approach?
Thanks!
VB Code:
Function RetainAspectRatio(ByVal imgHeight As Integer, ByVal imgWidth As Integer, ByVal IsItASmallThumb As Boolean) As ArrayList Dim blnSizeCheck As Boolean = IsItASmallThumb Dim maxheight As Integer Dim maxwidth As Integer If blnSizeCheck Then maxheight = 93 maxwidth = 125 Else maxheight = 300 maxwidth = 400 End If imgHeight = Convert.ToDouble(imgHeight) imgWidth = Convert.ToDouble(imgWidth) 'Get the new height and width depending on whether the end result will be a small thumb or medium-size image 'image If (imgWidth > imgHeight) Or (imgWidth = imgHeight) Then While imgWidth > maxwidth imgWidth = Math.Round(imgWidth - (imgWidth * 0.01), 0) imgHeight = Math.Round(imgHeight - (imgHeight * 0.01), 0) End While ElseIf imgHeight > imgWidth Then While (imgHeight > maxheight) Or (imgWidth > maxwidth) imgWidth = Math.Round(imgWidth - (imgWidth * 0.01), 0) imgHeight = Math.Round(imgHeight - (imgHeight * 0.01), 0) End While End If 'send the new dimensions back in an arraylist imgWidth = Convert.ToInt32(imgWidth) imgHeight = Convert.ToInt32(imgHeight) Dim arDimensions As New ArrayList arDimensions.Add(imgWidth) arDimensions.Add(imgHeight) Return arDimensions End Function




Reply With Quote