jpg file dimension retrieval 
Author Message
 jpg file dimension retrieval

Hi everyone, I have a big problem I would like help with.

Here is the deal, I am having to retrieve jpg images from a MS-SQL
Server in the image data type.  I will be displaying these images on
the web, but I need to scaled them down.  So I need to get the
dimension of the picture from it.  I have a couple peices of code that
i have tried but i always get the wrong thing.  I'm going to post the
pieces i think are buggy and if anyone can see anything wrong, please
let me know.  My suspicions are that I am looking for the wrong marker
within the jpg file.

I am displaying the image just fine, but when looking for the
dimensions, I get h=-1 w=-1 for the first segment of code, and h=55554
w=255 for the second.

Here is the first:

 lngPos = 1
 ExitLoop = false

 do while ExitLoop = False and lngPos < mLngSize

    do while AscB(midb(mStrBinaryData, lngPos, 1)) = 255 and lngPos <
mLngSize
       lngPos = lngPos + 1
    loop

    if AscB(midb(mStrBinaryData, lngPos, 1)) < 192 or
AscB(midb(mStrBinaryData, lngPos, 1)) > 195 then
       lngMarkerSize = lngConvert2(midb(mStrBinaryData, lngPos + 1,
2))
       lngPos = lngPos + lngMarkerSize  + 1
    else
       ExitLoop = True
    end if

loop
'
if ExitLoop = False then

   mLngWidth = -1
   mLngHeight = -1
   'Depth = -1

else

   mLngHeight = lngConvert2(midb(mStrBinaryData, lngPos + 4, 2))
   mLngWidth = lngConvert2(midb(mStrBinaryData, lngPos + 6, 2))
   'Depth = 2 ^ (asc(mid(mStrBinaryData, lngPos + 8, 1)) * 8)
   'gfxSpex = True

end if

_______________________
Here is the second:

' Prefix found before image dimensions
lBinPrefix = ChrB(&h00) & ChrB(&h11) & ChrB(&h08)

' Find the last prefix (so we don't confuse it with data)              
lLngStart = 1
Do
        If InStrB(lLngStart, mStrBinaryData, lBinPrefix) + 3 = 3 Then Exit Do
        lLngStart = InStrB(lLngStart, mStrBinaryData, lBinPrefix) + 3
Loop

' If a prefix was found
If Not lLngStart = 1 Then
        mLngWidth = CLng("&h" & HexAt(lngStart+2) & HexAt(lngStart+3))
        mLngHeight = CLng("&h" & HexAt(lngStart) & HexAt(lngStart+1))
End If



Mon, 05 Jul 2004 04:39:56 GMT  
 jpg file dimension retrieval
hi, use LoadPicture in VBScript

--

Saludos
Alejandro Sfrede



Quote:
> Hi everyone, I have a big problem I would like help with.

> Here is the deal, I am having to retrieve jpg images from a MS-SQL
> Server in the image data type.  I will be displaying these images on
> the web, but I need to scaled them down.  So I need to get the
> dimension of the picture from it.  I have a couple peices of code that
> i have tried but i always get the wrong thing.  I'm going to post the
> pieces i think are buggy and if anyone can see anything wrong, please
> let me know.  My suspicions are that I am looking for the wrong marker
> within the jpg file.

> I am displaying the image just fine, but when looking for the
> dimensions, I get h=-1 w=-1 for the first segment of code, and h=55554
> w=255 for the second.

> Here is the first:

>  lngPos = 1
>  ExitLoop = false

>  do while ExitLoop = False and lngPos < mLngSize

>     do while AscB(midb(mStrBinaryData, lngPos, 1)) = 255 and lngPos <
> mLngSize
>        lngPos = lngPos + 1
>     loop

>     if AscB(midb(mStrBinaryData, lngPos, 1)) < 192 or
> AscB(midb(mStrBinaryData, lngPos, 1)) > 195 then
>        lngMarkerSize = lngConvert2(midb(mStrBinaryData, lngPos + 1,
> 2))
>        lngPos = lngPos + lngMarkerSize  + 1
>     else
>        ExitLoop = True
>     end if

> loop
> '
> if ExitLoop = False then

>    mLngWidth = -1
>    mLngHeight = -1
>    'Depth = -1

> else

>    mLngHeight = lngConvert2(midb(mStrBinaryData, lngPos + 4, 2))
>    mLngWidth = lngConvert2(midb(mStrBinaryData, lngPos + 6, 2))
>    'Depth = 2 ^ (asc(mid(mStrBinaryData, lngPos + 8, 1)) * 8)
>    'gfxSpex = True

> end if

> _______________________
> Here is the second:

> ' Prefix found before image dimensions
> lBinPrefix = ChrB(&h00) & ChrB(&h11) & ChrB(&h08)

> ' Find the last prefix (so we don't confuse it with data)
> lLngStart = 1
> Do
> If InStrB(lLngStart, mStrBinaryData, lBinPrefix) + 3 = 3 Then Exit Do
> lLngStart = InStrB(lLngStart, mStrBinaryData, lBinPrefix) + 3
> Loop

> ' If a prefix was found
> If Not lLngStart = 1 Then
> mLngWidth = CLng("&h" & HexAt(lngStart+2) & HexAt(lngStart+3))
> mLngHeight = CLng("&h" & HexAt(lngStart) & HexAt(lngStart+1))
> End If



Mon, 05 Jul 2004 06:20:13 GMT  
 jpg file dimension retrieval
The VBSource code for it can be found at:

http://www.aspfaq.com/show.asp?id=2170

There are several variations of JPG layout, so you have to be careful.  This
version seems to be the most accurate I've found without using a COM object.

Good luck!

    Bryan
    www.chameleon-systems.com


Quote:
> Hi everyone, I have a big problem I would like help with.

> Here is the deal, I am having to retrieve jpg images from a MS-SQL
> Server in the image data type.  I will be displaying these images on
> the web, but I need to scaled them down.  So I need to get the
> dimension of the picture from it.  I have a couple peices of code that
> i have tried but i always get the wrong thing.  I'm going to post the
> pieces i think are buggy and if anyone can see anything wrong, please
> let me know.  My suspicions are that I am looking for the wrong marker
> within the jpg file.

> I am displaying the image just fine, but when looking for the
> dimensions, I get h=-1 w=-1 for the first segment of code, and h=55554
> w=255 for the second.

> Here is the first:

>  lngPos = 1
>  ExitLoop = false

>  do while ExitLoop = False and lngPos < mLngSize

>     do while AscB(midb(mStrBinaryData, lngPos, 1)) = 255 and lngPos <
> mLngSize
>        lngPos = lngPos + 1
>     loop

>     if AscB(midb(mStrBinaryData, lngPos, 1)) < 192 or
> AscB(midb(mStrBinaryData, lngPos, 1)) > 195 then
>        lngMarkerSize = lngConvert2(midb(mStrBinaryData, lngPos + 1,
> 2))
>        lngPos = lngPos + lngMarkerSize  + 1
>     else
>        ExitLoop = True
>     end if

> loop
> '
> if ExitLoop = False then

>    mLngWidth = -1
>    mLngHeight = -1
>    'Depth = -1

> else

>    mLngHeight = lngConvert2(midb(mStrBinaryData, lngPos + 4, 2))
>    mLngWidth = lngConvert2(midb(mStrBinaryData, lngPos + 6, 2))
>    'Depth = 2 ^ (asc(mid(mStrBinaryData, lngPos + 8, 1)) * 8)
>    'gfxSpex = True

> end if

> _______________________
> Here is the second:

> ' Prefix found before image dimensions
> lBinPrefix = ChrB(&h00) & ChrB(&h11) & ChrB(&h08)

> ' Find the last prefix (so we don't confuse it with data)
> lLngStart = 1
> Do
> If InStrB(lLngStart, mStrBinaryData, lBinPrefix) + 3 = 3 Then Exit Do
> lLngStart = InStrB(lLngStart, mStrBinaryData, lBinPrefix) + 3
> Loop

> ' If a prefix was found
> If Not lLngStart = 1 Then
> mLngWidth = CLng("&h" & HexAt(lngStart+2) & HexAt(lngStart+3))
> mLngHeight = CLng("&h" & HexAt(lngStart) & HexAt(lngStart+1))
> End If



Mon, 05 Jul 2004 09:04:09 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. jpg file dimension retrieval

2. Help - Formating during TBatchCopy

3. DELPHI: Need info on delphi's memory limitation.

4. Help, why won't it work on FPC?

5. Dimensions of GIF and JPG from files

6. Using VBA in A2k to get dimensions of a jpg file

7. Jpg File Dimensions / Html

8. Help! - jpg file dimensions

9. Dimensions of GIF and JPG from files

10. .bmp, .gif, .jpg dimensions

11. ? How to get dimensions of gif or jpg

12. Dimensions on gif / jpg

 

 
Powered by phpBB® Forum Software