работает через коммандную строку
типа:
Jpeg_Themb.exe example.jpg
Со всеми видами кодировок Jpeg не проверял...
- Код: Выделить всё
#COMPILE EXE
#DIM ALL
DECLARE FUNCTION find_start_of_image() AS LONG
DECLARE FUNCTION extract_thumbnail() AS LONG
GLOBAL k AS LONG
GLOBAL temp2 AS BYTE
GLOBAL place_in_file AS LONG
GLOBAL result AS LONG
GLOBAL m AS LONG
GLOBAL afile AS STRING
'*---------------------------------------------------------------------------------------------------------*/
FUNCTION PBMAIN () AS LONG
afile = TRIM$(COMMAND$)
IF afile <> "" THEN
! mov place_in_file,0
OPEN afile FOR BINARY AS 1
IF 0 = find_start_of_image() THEN
CALL extract_thumbnail()
ELSE
MSGBOX "No thumbnail found."
END IF
CLOSE 1
END IF
END FUNCTION
'*---------------------------------------------------------------------------------------------------------*/
FUNCTION find_start_of_image() AS LONG
' searching for JPEG header
WHILE ISFALSE EOF(1)
'looking for start of JPEG marker
GET 1,,temp2
! inc place_in_file
IF temp2<0 THEN FUNCTION = 1: EXIT FUNCTION
IF temp2=255 THEN
' first 1/2 of JPEG marker found, looking for second half.
GET 1,,temp2
! inc place_in_file
IF temp2<0 THEN FUNCTION = 1: EXIT FUNCTION
IF temp2=216 THEN
' second 1/2 of JPEG marker found.
WHILE ISFALSE EOF(1)
' looking for second JPEG marker
GET 1,,temp2
! inc place_in_file
IF temp2<0 THEN FUNCTION = 1: EXIT FUNCTION
IF temp2=255 THEN
' first 1/2 of 2dn JPEG marker found, looking for second half.
GET 1,,temp2
! inc place_in_file
IF temp2<0 THEN FUNCTION = 1: EXIT FUNCTION
IF temp2=216 THEN
' second 1/2 of 2nd JPEG marker found.
' JPEG SOI marker found at
place_in_file = place_in_file - 1
SEEK 1,place_in_file
FUNCTION = 0: EXIT FUNCTION
END IF
IF temp2=217 THEN
FUNCTION = 1: EXIT FUNCTION
END IF
END IF
WEND
END IF
END IF
WEND
FUNCTION = 1
END FUNCTION
'*---------------------------------------------------------------------------------------------------------*/
FUNCTION extract_thumbnail() AS LONG
OPEN "_" & afile FOR BINARY AS 2
WHILE ISFALSE EOF(1)
GET 1,,temp2
PUT 2,,temp2
IF temp2=255 THEN
GET 1,,temp2
PUT 2,,temp2
IF temp2=217 THEN
CLOSE 2
FUNCTION = 0
EXIT FUNCTION
END IF
END IF
WEND
CLOSE 2
FUNCTION = 1
END FUNCTION