Results 1 to 4 of 4

Thread: resizing a image

  1. #1
    Join Date
    Nov 2005

    resizing a image

    Hi, I need to know if it is possible ot resize a image in asp and if any1 has the line of code for it that would be great. I dont want the actual image file to be resized just the image that I am displaying.

  2. #2
    Join Date
    Jun 2003
    Indiana, USA
    Why don't you just use the <image height="" width=""> format?
    Last edited by chrismartz; 02-25-2006 at 02:09 PM.
    Some things Man was never meant to know. For everything else, there's Google.

  3. #3
    Join Date
    Feb 2006
    Bhubaneswar, Orissa
    Here is the solution

    Following set of code gets the width and height of an image dynamically and also calculates the desired dimention proportionately.

    GetJpegDims-> Displays the Height and Width of an image dynamically
    resizeGraphic -> Resizes the height and proportionately, you need to provide the max and min height and widths


    dim lngHeight
    dim lngWidth
    dim displayHeight
    dim displayWidth
    dim strFileName
    strFileName = "sample.jpg"
    GetJpegDims strFileName ,lngHeight,lngWidth
    call resizeGraphic

    Sub GetJpegDims(ByVal strFileName, ByRef lngHeight, ByRef lngWidth)
    'on error resume next
    Dim stmFile
    set stmFile = server.createobject("ADODB.Stream")
    Dim bytArr(256)
    dim byt
    Dim intPos
    With stmFile
    .Type = adTypeBinary
    .LoadFromFile strFileName
    .Position = 0

    for intPos = 0 to 255
    .position = intpos
    bytArr(intPos) = ascb(.Read(1))
    End With
    Set stmFile = Nothing

    For intPos = 0 To 255
    If bytArr(intPos) = &HFF And bytArr(intPos + 1) >= &HC0 _
    And bytArr(intPos + 1) <= &HCF Then
    lngHeight = bytArr(intPos + 5) * 256 + bytArr(intPos + 6)
    lngWidth = bytArr(intPos + 7) * 256 + bytArr(intPos + 8)
    Exit For
    End If
    End Sub

    Sub resizeGraphic
    'Flag used to see if the image didn't conform to our required dimension limits
    dim blnBadSize

    '*** Predefined Image Limits
    '*** Maximums
    maximumHeight = 480
    maximumWidth = 250

    '*** Minimums
    minimumHeight = 100
    minimumWidth = 100

    '*** Dimensions used to display the image
    displayHeight = lngHeight
    displayWidth = lngWidth

    '*** Check to see if the image is too large and resize it proportionately if it is

    If displayWidth > maximumWidth Then
    displayHeight = displayHeight * maximumWidth / displayWidth
    displayWidth = maximumWidth
    blnBadSize = True
    End If

    If displayHeight > maximumHeight Then
    displayWidth = displayWidth * maximumHeight / displayHeight
    displayHeight = maximumHeight
    blnBadSize = True
    End If

    If displayWidth < minimumWidth or displayHeight < minimumHeight Then
    '*** The image is too small but we will display it at its current size
    blnBadSize = True
    End If

    End Sub


    in the html use this

    <img src="sample.jpg" width="<%=displayWidth%>" height="<%=displayHeight%>">

    Hope this solves ur prob


    Last edited by cosmoquest; 02-25-2006 at 02:14 PM.

  4. #4
    Join Date
    Jan 2003
    Why don't you just use the <image height="" width=""> format?
    I agree and you can even just set just the height or just the width and let the image retain its original proportions:

    <img src="myimage.gif" height="50">
    J. Paul Schmidt
    www.Bullschmidt.com - Freelance Web and Database Developer
    www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center