******************************************************************
* Check if a file is a bmp , gif , jpg or png
* Optional width and height of the image is compared with maximum values .
******************************************************************
* Return value is
* 0 - success
* 1 - none of the accepted type
* 2 - too wide
* 4 - too high
******************************************************************
* is_pic can be called with 1-3 parameters:
* - image file
* - maximum width
* - maximum height
******************************************************************
FUNCTION is_pic
LPARAMETERS lcFil,lnwidthm,lnheightm
LOCAL llIspict
llIspict=is_png(m.lcFil,m.lnwidthm,m.lnheightm)
IF m.llIspict!=1
RETURN m.llIspict
ELSE
llIspict=is_gif(m.lcFil,m.lnwidthm,m.lnheightm)
IF m.llIspict!=1
RETURN m.llIspict
ELSE
llIspict=is_bmp(m.lcFil,m.lnwidthm,m.lnheightm)
IF m.llIspict!=1
RETURN m.llIspict
ELSE
llIspict=is_jpg(m.lcFil,m.lnwidthm,m.lnheightm)
RETURN llIspict
ENDIF
ENDIF
ENDIF
******************************************************************
* Check if a file is a bmp
* Optional width and height of the image is compared with maximum values .
******************************************************************
* Return value is
* 0 - success
* 1 - not a BMP
* 2 - too wide
* 4 - too high
******************************************************************
* is_bmp can be called with 1-3 parameters:
* - image file
* - maximum width
* - maximum height
******************************************************************
FUNCTION is_bmp
LPARAMETERS lcFil,lnwidthm,lnheightm
LOCAL lcS,llSgn,lnWidth,lnHeight,llIsbmp,llIsWidth,llIsHeight
llIsbmp=0
llIsWidth=PCOUNT()>1 and VARTYPE(m.lnwidthm)="N"
IF m.llIsWidth
llIsWidth=m.lnwidthm>0
ENDIF
llIsHeight=PCOUNT()>1 and VARTYPE(m.lnheightm)="N"
IF m.llIsHeight
llIsHeight=m.lnheightm>0
ENDIF
lcs=FILETOSTR(FULLPATH(m.lcfil))
llsgn=ASC(SUBSTR(m.lcs,1,1))=66 and ASC(SUBSTR(m.lcs,2,1))=77
IF m.llsgn
lnwidth=ASC(SUBSTR(m.lcs,17))*256*256+ASC(SUBSTR(m.lcs,18))*256*256*256+ASC(SUBSTR(m.lcs,19))+ASC(SUBSTR(m.lcs,20))*256
IF m.llIsWidth
IF m.lnwidth>m.lnwidthm
llIsbmp=m.llIsbmp+2
ENDIF
ENDIF
lnheight=ASC(SUBSTR(m.lcs,21))*256*256+ASC(SUBSTR(m.lcs,22))*256*256*256+ASC(SUBSTR(m.lcs,23))+ASC(SUBSTR(m.lcs,24))*256
IF m.llIsHeight
IF m.lnheight>m.lnheightm
llIsbmp=m.llIsbmp+4
ENDIF
ENDIF
ELSE
llIsbmp=m.llIsbmp+1
ENDIF
RETURN m.llIsbmp
******************************************************************
* Check if a file is png
* Optional width and height of the image is compared with maximum values .
******************************************************************
* Return value is
* 0 - success
* 1 - not a PNG
* 2 - too wide
* 4 - too high
******************************************************************
* is_png can be called with 1-3 parameters:
* - image file
* - maximum width
* - maximum height
******************************************************************
FUNCTION is_png
LPARAMETERS lcFil,lnwidthm,lnheightm
LOCAL lcS,llSgn,lnWidth,lnHeight,llIspng,llIsWidth,llIsHeight
llIspng=0
llIsWidth=PCOUNT()>1 and VARTYPE(m.lnwidthm)="N"
IF m.llIsWidth
llIsWidth=m.lnwidthm>0
ENDIF
llIsHeight=PCOUNT()>1 and VARTYPE(m.lnheightm)="N"
IF m.llIsHeight
llIsHeight=m.lnheightm>0
ENDIF
lcs=FILETOSTR(FULLPATH(m.lcfil))
llsgn=ASC(SUBSTR(m.lcs,1,1))=137 and ASC(SUBSTR(m.lcs,2,1))=80 and ASC(SUBSTR(m.lcs,3,1))=78 and ASC(SUBSTR(m.lcs,4,1))=71 and ASC(SUBSTR(m.lcs,5,1))=13 and ASC(SUBSTR(m.lcs,6,1))=10 and ASC(SUBSTR(m.lcs,7,1))=26 and ASC(SUBSTR(m.lcs,8,1))=10
IF m.llsgn
lnwidth=ASC(SUBSTR(m.lcs,17))*256*256*256+ASC(SUBSTR(m.lcs,18))*256*256+ASC(SUBSTR(m.lcs,19))*256+ASC(SUBSTR(m.lcs,20))
IF m.llIsWidth
IF m.lnwidth>m.lnwidthm
llIspng=m.llIspng+2
ENDIF
ENDIF
lnheight=ASC(SUBSTR(m.lcs,21))*256*256*256+ASC(SUBSTR(m.lcs,22))*256*256+ASC(SUBSTR(m.lcs,23))*256+ASC(SUBSTR(m.lcs,24))
IF m.llIsHeight
IF m.lnheight>m.lnheightm
llIspng=m.llIspng+4
ENDIF
ENDIF
ELSE
llIspng=m.llIspng+1
ENDIF
RETURN m.llIspng
******************************************************************
* Check if a file is a gif
* Optional width and height of the image is compared with maximum values .
******************************************************************
* Return value is
* 0 - success
* 1 - not a GIF
* 2 - too wide
* 4 - too high
******************************************************************
* is_gif can be called with 1-3 parameters:
* - image file
* - maximum width
* - maximum height
******************************************************************
FUNCTION is_gif
LPARAMETERS lcFil,lnwidthm,lnheightm
LOCAL lcS,llSgn,lnWidth,lnHeight,llIsgif,llIsWidth,llIsHeight
llIsgif=0
llIsWidth=PCOUNT()>1 and VARTYPE(m.lnwidthm)="N"
IF m.llIsWidth
llIsWidth=m.lnwidthm>0
ENDIF
llIsHeight=PCOUNT()>1 and VARTYPE(m.lnheightm)="N"
IF m.llIsHeight
llIsHeight=m.lnheightm>0
ENDIF
lcs=FILETOSTR(FULLPATH(m.lcfil))
llsgn=ASC(SUBSTR(m.lcs,1,1))=71 and ASC(SUBSTR(m.lcs,2,1))=73 and ASC(SUBSTR(m.lcs,3,1))=70
IF m.llsgn
lnwidth=ASC(SUBSTR(m.lcs,7))+ASC(SUBSTR(m.lcs,8))*256
IF m.llIsWidth
IF m.lnwidth>m.lnwidthm
llIsgif=m.llIsgif+2
ENDIF
ENDIF
lnheight=ASC(SUBSTR(m.lcs,9))+ASC(SUBSTR(m.lcs,10))*256
IF m.llIsHeight
IF m.lnheight>m.lnheightm
llIsgif=m.llIsgif+4
ENDIF
ENDIF
ELSE
llIsgif=m.llIsgif+1
ENDIF
RETURN m.llIsgif
******************************************************************
* Check if a file is a jpg
* Optional width and height of the image is compared with maximum values .
******************************************************************
* Return value is
* 0 - success
* 1 - not a JPG
* 2 - too wide
* 4 - too high
******************************************************************
* is_jpg can be called with 1-3 parameters:
* - image file
* - maximum width
* - maximum height
******************************************************************
FUNCTION is_jpg
LPARAMETERS lcFil,lnwidthm,lnheightm
LOCAL lcS,llSgn,lnWidth,lnHeight,llIsjpg,lnstart,lni,llIsWidth,llIsHeight
llIsjpg=0
llIsWidth=PCOUNT()>1 and VARTYPE(m.lnwidthm)="N"
IF m.llIsWidth
llIsWidth=m.lnwidthm>0
ENDIF
llIsHeight=PCOUNT()>1 and VARTYPE(m.lnheightm)="N"
IF m.llIsHeight
llIsHeight=m.lnheightm>0
ENDIF
lcs=FILETOSTR(FULLPATH(m.lcfil))
llsgn=.F.
STORE 0 TO m.lnwidth,m.lnheight
FOR lni=1 TO LEN(m.lcs)-2
IF ASC(SUBSTR(m.lcs,m.lni,1))=255 and ASC(SUBSTR(m.lcs,m.lni+1,1))=216 and ASC(SUBSTR(m.lcs,m.lni+2,1))=255
llsgn=.T.
lnstart=m.lni+2
EXIT
ENDIF
NEXT
IF m.llsgn
lni=m.lnstart
DO WHILE m.lni<LEN(m.lcs)
IF ASC(SUBSTR(m.lcs,m.lni,1))=255 and ASC(SUBSTR(m.lcs,m.lni+1,1))!=255
IF INLIST(ASC(SUBSTR(m.lcs,m.lni+1,1)),0xC0,0xC1,0xC2,0xC3,0xC5,0xC6,0xC7,0xC9,0xCA,0xCB,0xCD,0xCE,0xCF)
lnwidth=ASC(SUBSTR(m.lcs,m.lni+6))+ASC(SUBSTR(m.lcs,m.lni+5))*256
IF m.llIsWidth
IF m.lnwidth>m.lnwidthm
llIsjpg=m.llIsjpg+2
ENDIF
ENDIF
lnheight=ASC(SUBSTR(m.lcs,m.lni+8))+ASC(SUBSTR(m.lcs,m.lni+7))*256
IF m.llIsHeight
IF m.lnheight>m.lnheightm
llIsjpg=m.llIsjpg+4
ENDIF
ENDIF
EXIT
ELSE
lni=m.lni+1+ASC(SUBSTR(m.lcs,m.lni+3))+ASC(SUBSTR(m.lcs,m.lni+2))*256
LOOP
ENDIF
ENDIF
lni=m.lni+1
ENDDO
ELSE
llIsjpg=m.llIsjpg+1
ENDIF
RETURN m.llIsjpg