/* Read width and height of a JPEG image */ Parse Arg FileName If FileName="" then Do Say "You must enter a filename..." Exit end /* do */ FileType=c2x(Charin(FileName,1,2)) If FileType="FFD8" then do NxtSeg=3 ImageHeight="IMAGEHEIGHT" Do While Type<>"D9" & NxtSeg<>-1 & Imageheight="IMAGEHEIGHT" NxtSeg=ReadSegment(NxtSeg) End rc=Stream(F,"C","Close") Say "Height:" ImageHeight Say "Width:" ImageWidth Say "Bits Per Sample:" ImageBPS end /* Do */ Else Do Say "This doesn't appear to be a JPEG file." Exit End Exit ReadSegment: /* Read a JPEG segment's header */ Arg SegPos Marker=C2X(CharIn(FileName, SegPos)) If Marker<>"FF" Then Return -1 Type=C2X(CharIn(FileName)) Res=SegPos+2 /* position of next segment */ Select When Type="01" | Type>="D0" & Type<="D9" Then /* No length to these */ Len=0 Otherwise Len=C2D(CharIn(FileName, , 2)) /* Read the length of the segment */ End Res=Res+Len If Type="C0" | Type="C2" Then Do /* start of frame 0 */ Imagebps=C2D(CharIn(FileName)) /* Bits per sample */ Imageheight=C2D(CharIn(FileName, , 2)) /* Height of image */ Imagewidth=C2D(CharIn(FileName, , 2)) /* Width of image */ End Return Res