Image Sizes

Discussion in 'ASP General' started by p byers, Dec 8, 2008.

  1. p byers

    p byers Guest

    Hello Folks,

    I have a WebSite that allows clients to upload 'ImageFiles'

    They are restricted to .JPG, .GIF and .PNG and a size of 100Kb.

    I have a page that will show the Images. The size is to be restricted.

    If the image height and width is less than the restricted size, the
    image is just centred in the 'Restricted Area'.

    If the image height or width is greater than the restricted size, the
    "IMG" tag has "height" & "width" parameters to contain it into the
    "Restricted Area".

    At the momement, the image size is obtained by the use of ServerObjects
    ASPImage Active X object.


    I need to put a copy of the page onto a server that does not have
    ASPImage installed.

    Is there any way I can get Image Width and Height without any special
    Active X 'es ??

    Thank you
    Pete (Northolt UK)
    p byers, Dec 8, 2008
    #1
    1. Advertising

  2. p byers

    Mike Brind Guest

    "p byers" <> wrote in message
    news:...
    > Hello Folks,
    >
    > I have a WebSite that allows clients to upload 'ImageFiles'
    >
    > They are restricted to .JPG, .GIF and .PNG and a size of 100Kb.
    >
    > I have a page that will show the Images. The size is to be restricted.
    >
    > If the image height and width is less than the restricted size, the
    > image is just centred in the 'Restricted Area'.
    >
    > If the image height or width is greater than the restricted size, the
    > "IMG" tag has "height" & "width" parameters to contain it into the
    > "Restricted Area".
    >
    > At the momement, the image size is obtained by the use of ServerObjects
    > ASPImage Active X object.
    >
    >
    > I need to put a copy of the page onto a server that does not have
    > ASPImage installed.
    >
    > Is there any way I can get Image Width and Height without any special
    > Active X 'es ??
    >


    Not unless you can use ASP.NET for that page.

    --
    Mike Brind
    MVP - ASP/ASP.NET
    Mike Brind, Dec 8, 2008
    #2
    1. Advertising

  3. p byers

    Roger Guest

    "p byers" <> wrote in message
    news:...
    > Hello Folks,
    >
    > I have a WebSite that allows clients to upload 'ImageFiles'
    >
    > They are restricted to .JPG, .GIF and .PNG and a size of 100Kb.
    >
    > I have a page that will show the Images. The size is to be restricted.
    >
    > If the image height and width is less than the restricted size, the
    > image is just centred in the 'Restricted Area'.
    >
    > If the image height or width is greater than the restricted size, the
    > "IMG" tag has "height" & "width" parameters to contain it into the
    > "Restricted Area".
    >
    > At the momement, the image size is obtained by the use of ServerObjects
    > ASPImage Active X object.
    >
    >
    > I need to put a copy of the page onto a server that does not have
    > ASPImage installed.
    >
    > Is there any way I can get Image Width and Height without any special
    > Active X 'es ??
    >
    > Thank you
    > Pete (Northolt UK)


    Hi Pete,

    I have an old bit of code which works for jpg and gif...

    set i = loadpicture(server.mappath(whatever))
    owidth = round(i.width / 26.4583)
    oheight = round(i.height / 26.4583)

    I don't recall why I had to divide by 26.4583, and it does need write
    permission on the file - or folder(?).

    For png the width + height seems to be bytes 16-20 and 21-24 (but check the
    spec, this code is ancient)
    so you can do...

    set o = server.CreateObject("ADODB.Stream")
    set fso = server.CreateObject("Scripting.FileSystemObject")
    set ff = fso.GetFile(server.mappath(f))
    o.Type = 1
    o_Open
    o.LoadFromFile(server.mappath(f))
    select case ff.type
    case "PNG Image"
    scanimg 24, 20, 24

    where scanimg is...

    function scanimg(f,w,h)
    dim s

    s = o.Read(f)
    if lenb(s) = f then
    owidth = clng(ascb(midb(s, w, 1)) + ((ascb(midb(s, w - 1, 1)) * 256)))
    oheight = clng(ascb(midb(s, h, 1)) + ((ascb(midb(s, h - 1, 1)) * 256)))
    end if

    end function

    That code only looks at two bytes rather than four, but you can see the
    idea.

    You can do similar things with bitmap, tif, gif, but jpeg is a right pain in
    the arse.

    Roger
    Roger, Dec 9, 2008
    #3
  4. p byers

    p byers Guest

    Jon
    Thanks - it is brilliant - just what I needed
    Pete (Northolt UK)

    "Jon Paal [MSMD]" wrote:

    > try this
    >
    > http://www.4guysfromrolla.com/webtech/code/imgsz.asp.html
    >
    > "p byers" <> wrote in message news:...
    > > Hello Folks,
    > >
    > > I have a WebSite that allows clients to upload 'ImageFiles'
    > >
    > > They are restricted to .JPG, .GIF and .PNG and a size of 100Kb.
    > >
    > > I have a page that will show the Images. The size is to be restricted.
    > >
    > > If the image height and width is less than the restricted size, the
    > > image is just centred in the 'Restricted Area'.
    > >
    > > If the image height or width is greater than the restricted size, the
    > > "IMG" tag has "height" & "width" parameters to contain it into the
    > > "Restricted Area".
    > >
    > > At the momement, the image size is obtained by the use of ServerObjects
    > > ASPImage Active X object.
    > >
    > >
    > > I need to put a copy of the page onto a server that does not have
    > > ASPImage installed.
    > >
    > > Is there any way I can get Image Width and Height without any special
    > > Active X 'es ??
    > >
    > > Thank you
    > > Pete (Northolt UK)
    > >
    p byers, Dec 9, 2008
    #4
  5. p byers

    p byers Guest

    Thanks for your reply

    Roger wrote:

    > "p byers" <> wrote in message
    > news:...
    > > Hello Folks,
    > >
    > > I have a WebSite that allows clients to upload 'ImageFiles'
    > >
    > > They are restricted to .JPG, .GIF and .PNG and a size of 100Kb.
    > >
    > > I have a page that will show the Images. The size is to be restricted.
    > >
    > > If the image height and width is less than the restricted size, the
    > > image is just centred in the 'Restricted Area'.
    > >
    > > If the image height or width is greater than the restricted size, the
    > > "IMG" tag has "height" & "width" parameters to contain it into the
    > > "Restricted Area".
    > >
    > > At the momement, the image size is obtained by the use of ServerObjects
    > > ASPImage Active X object.
    > >
    > >
    > > I need to put a copy of the page onto a server that does not have
    > > ASPImage installed.
    > >
    > > Is there any way I can get Image Width and Height without any special
    > > Active X 'es ??
    > >
    > > Thank you
    > > Pete (Northolt UK)

    >
    > Hi Pete,
    >
    > I have an old bit of code which works for jpg and gif...
    >
    > set i = loadpicture(server.mappath(whatever))
    > owidth = round(i.width / 26.4583)
    > oheight = round(i.height / 26.4583)
    >
    > I don't recall why I had to divide by 26.4583, and it does need write
    > permission on the file - or folder(?).
    >
    > For png the width + height seems to be bytes 16-20 and 21-24 (but check the
    > spec, this code is ancient)
    > so you can do...
    >
    > set o = server.CreateObject("ADODB.Stream")
    > set fso = server.CreateObject("Scripting.FileSystemObject")
    > set ff = fso.GetFile(server.mappath(f))
    > o.Type = 1
    > o_Open
    > o.LoadFromFile(server.mappath(f))
    > select case ff.type
    > case "PNG Image"
    > scanimg 24, 20, 24
    >
    > where scanimg is...
    >
    > function scanimg(f,w,h)
    > dim s
    >
    > s = o.Read(f)
    > if lenb(s) = f then
    > owidth = clng(ascb(midb(s, w, 1)) + ((ascb(midb(s, w - 1, 1)) * 256)))
    > oheight = clng(ascb(midb(s, h, 1)) + ((ascb(midb(s, h - 1, 1)) * 256)))
    > end if
    >
    > end function
    >
    > That code only looks at two bytes rather than four, but you can see the
    > idea.
    >
    > You can do similar things with bitmap, tif, gif, but jpeg is a right pain in
    > the arse.
    >
    > Roger
    p byers, Dec 9, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Stephen
    Replies:
    2
    Views:
    563
    David Stephen
    Jul 10, 2003
  2. coleenholley
    Replies:
    5
    Views:
    1,127
    coleenholley
    Jan 21, 2004
  3. Greg Smith

    Changing control sizes

    Greg Smith, Jan 26, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    326
    Eliyahu Goldin
    Jan 26, 2005
  4. Dan Polansky
    Replies:
    3
    Views:
    786
    Larry Barowski
    Feb 12, 2007
  5. Chitty
    Replies:
    0
    Views:
    156
    Chitty
    Oct 19, 2004
Loading...

Share This Page