* usage STORE 0 TO x, y getpictdimensions(getpict(),@x,@y) ? x,y PROCEDURE GetPictDimensions LPARAMETERS cFileName, nWidth, nHeight LOCAL lnImg, lnGet STORE -1 TO nWidth, nHeight * try to open picture file IF FILE(cFileName) lnImg = FOPEN(cFileName,10) IF lnImg>=0 * successfully opened, so get first two bytes lcChars = FREAD(lnImg,2) DO CASE * 0xFFD8 signals a jpeg image CASE lcChars = CHR(0xFF)+CHR(0xD8) * fetch next marker DO WHILE !FEOF(lnImg) lcChars = FREAD(lnImg,1) * found a marker IF lcChars=CHR(0xFF) * must discard extra 0xFFs DO WHILE lcChars=CHR(0xFF) lcChars = FREAD(lnImg,1) ENDDO * is this the SOF marker? IF BETWEEN(ASC(lcChars),0xC0,0xC3) FREAD(lnImg,3) * read dimensions lcChars = FREAD(lnImg,1) nHeight = ASC(lcChars)*256 lcChars = FREAD(lnImg,1) nHeight = nHeight+ASC(lcChars) lcChars = FREAD(lnImg,1) nWidth = ASC(lcChars)*256 lcChars = FREAD(lnImg,1) nWidth = nWidth+ASC(lcChars) EXIT * if not, jump to the next marker ELSE * get the offset lcChars = FREAD(lnImg,1) lnOffset = ASC(lcChars)*256 lcChars = FREAD(lnImg,1) lnOffset = lnOffset+ASC(lcChars) * go ahead to next marker IF lnOffset>2 FSEEK(lnImg,lnOffset-2,1) ELSE EXIT ENDIF ENDIF ENDIF ENDDO * if not a jpeg image, go for a gif CASE lcChars = "GI" * look for remain gif signal lcChars = FREAD(lnImg,4) IF INLIST(lcChars,"F87a","F89a") * it's a GIF file, fetch logical screen size lcChars = FREAD(lnImg,1) nWidth = ASC(lcChars) lcChars = FREAD(lnImg,1) nWidth = nWidth+ASC(lcChars)*256 lcChars = FREAD(lnImg,1) nHeight = ASC(lcChars) lcChars = FREAD(lnImg,1) nHeight = nHeight+ASC(lcChars)*256 ENDIF ENDCASE FCLOSE(lnImg) ENDIF ENDIF ENDPROC