G
Gonzosez
I need to resize images to a fixed width.
How can I hold the aspect ratio?
Thanks
How can I hold the aspect ratio?
Thanks
Ray at said:Decrease the height by the same percentage.
iCurrentWidth = 100
iCurrentHeight = 54
iDesiredWidth = 70
iPercentDecreased = iDesiredWidth/iCurrentWidth
iNewHeight = CInt(iCurrentHeight * iPercentDecreased)
Ray at work
William Morris said:Not so! Don't remember where I found this but if you're using IIS 5.0 this
ought to work...(at least, it does for me)
Function GetScaledImageDimensions(strPicturePath, imgWidth, imgHeight)
dim picture, actualWidth, actualHeight, decProportion
'--- as inputs, imgWidth and imgHeight are used as target sizes.
'--- if imgWidth > 0 then imgHeight is adjusted proportionately, and vice
versa.
'--- to return the actual width and height, leave both at zero
On Error Resume Next
Set Picture = LoadPicture(strPicturePath)
If Err <> 0 Then
imgWidth = 0
imgHeight = 0
Else
actualWidth = Round(Picture.Width / 26.5)
actualHeight = Round(Picture.Height / 26.5)
if imgWidth > 0 and imgHeight = 0 then
decProportion = imgWidth / actualWidth
elseif imgWidth = 0 and imgHeight > 0 then
decProportion = imgHeight / actualHeight
else
decProportion = 1
end if
imgWidth = Round(actualWidth * decProportion)
imgHeight = Round(actualHeight * decProportion)
End If
Set Picture = nothing
End Function
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.