JPG Meta Data

JPG Meta Data

Postby Jack » Thu Aug 06, 2009 9:57 am

Hello,

I see with the advanced properties of a jpg files that there is lot of information such :
Date + time , resolution ... .

How is it possible to extract Meta data associated with JPG or TIFF files with fivewin in order to save them in a dbf file ?

Thanks .
Jack
 
Posts: 288
Joined: Wed Jul 11, 2007 11:06 am

Re: JPG Meta Data

Postby nageswaragunupudi » Thu Aug 06, 2009 3:44 pm

FreeImage Library's GetMetaData / GetTag functions provide the facility to read metadata of jpeg files.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: JPG Meta Data

Postby Enrico Maria Giordano » Sat Aug 08, 2009 11:03 am

This is a sample:

Code: Select all  Expand view
#include "Fivewin.ch"


STATIC hLibFI


FUNCTION MAIN()

    ? GETTAGVALUE( "PROVA.JPG", "Make" )
    ? GETTAGVALUE( "PROVA.JPG", "DateTime" )
    ? GETTAGVALUE( "PROVA.JPG", "XResolution" )
    ? GETTAGVALUE( "PROVA.JPG", "YResolution" )
    ? GETTAGVALUE( "PROVA.JPG", "NonExistent" )

    ? SETCOMMENTS( "PROVA.JPG", "Questa è una prova di commento" )
    ? GETCOMMENTS( "PROVA.JPG" )

    RETURN NIL


#define FIMD_COMMENTS  0
#define FIMD_EXIF_MAIN 1
#define FIMD_IPTC      6
#define FIMD_XMP       7

#define FIDT_ASCII 2


FUNCTION GETCOMMENTS( cFile )

    RETURN GETTAGVALUE( cFile, "Comment", FIMD_COMMENTS )


FUNCTION SETCOMMENTS( cFile, cComment )

    RETURN SETTAGVALUE( cFile, "Comment", cComment, FIMD_COMMENTS )


FUNCTION GETIPTCVALUE( cFile, cKey )

    RETURN GETTAGVALUE( cFile, cKey, FIMD_IPTC )


FUNCTION GETTAGVALUE( cFile, cKey, cModel )

    LOCAL nFormat, hDib, nTagPtr, nType, xValue

    DEFAULT cModel := FIMD_EXIF_MAIN

    hLibFI = LOADLIBRARY( "freeimage.dll" )

    nFormat = FIGETFILETYPE( cFile, 0 )
    hDib    = FILOAD( nFormat, cFile, 0 )

    FIGETMETADATA( cModel, hDib, cKey, @nTagPtr )

    IF nTagPtr != 0
        nType = FIGETTAGTYPE( nTagPtr )

        xValue = FIGETTAGVALUE( nTagPtr )

        IF nType != 2
            xValue = BIN2L( xValue )
        ENDIF
    ENDIF

    FIUNLOAD( hDib )

    FREELIBRARY( hLibFI )

    RETURN xValue


FUNCTION SETTAGVALUE( cFile, cKey, cValue, cModel )

    LOCAL nFormat, hDib, nTagPtr

    LOCAL lOk := .F.

    DEFAULT cModel := FIMD_EXIF_MAIN

    hLibFI = LOADLIBRARY( "freeimage.dll" )

    nFormat = FIGETFILETYPE( cFile, 0 )
    hDib    = FILOAD( nFormat, cFile, 0 )

    BEGIN SEQUENCE
        nTagPtr = FICREATETAG()

        IF nTagPtr = 0; BREAK; ENDIF

        lOk = FISETTAGKEY( nTagPtr, cKey )

        IF !lOk; BREAK; ENDIF

        lOk = FISETTAGLENGTH( nTagPtr, LEN( cValue ) )

        IF !lOk; BREAK; ENDIF

        lOk = FISETTAGCOUNT( nTagPtr, LEN( cValue ) )

        IF !lOk; BREAK; ENDIF

        lOk = FISETTAGTYPE( nTagPtr, FIDT_ASCII )

        IF !lOk; BREAK; ENDIF

        lOk = FISETTAGVALUE( nTagPtr, cValue )

        IF !lOk; BREAK; ENDIF

        lOk = FISETMETADATA( cModel, hDib, cKey, nTagPtr )

        IF !lOk; BREAK; ENDIF

        lOk = FISAVE( nFormat, hDib, "PROVANUOVO.JPG", 100 )
    END SEQUENCE

    FIDELETETAG( nTagPtr )

    FIUNLOAD( hDib )

    FREELIBRARY( hLibFI )

    RETURN lOk


DLL STATIC FUNCTION FIGETFILETYPE( cFileName AS LPSTR, nSize AS LONG ) AS LONG;
    PASCAL FROM "_FreeImage_GetFileType@8" LIB hLibFI

DLL STATIC FUNCTION FILOAD( nFormat AS LONG, cFileName AS LPSTR, nFlags AS LONG ) AS LONG;
    PASCAL FROM "_FreeImage_Load@12" LIB hLibFI

DLL STATIC FUNCTION FISAVE( nFormat AS LONG, hDib AS LONG, cFileName AS LPSTR, nFlags AS LONG ) AS BOOL;
    PASCAL FROM "_FreeImage_Save@16" LIB hLibFI

DLL STATIC FUNCTION FIGETMETADATA( nModel AS LONG, hDib AS LONG, cKey AS LPSTR, @nTag AS PTR ) AS BOOL;
    PASCAL FROM "_FreeImage_GetMetadata@16" LIB hLibFI

DLL STATIC FUNCTION FIGETTAGTYPE( nTag AS LONG ) AS LONG;
    PASCAL FROM "_FreeImage_GetTagType@4" LIB hLibFI

DLL STATIC FUNCTION FIGETTAGVALUE( nTag AS LONG ) AS LPSTR;
    PASCAL FROM "_FreeImage_GetTagValue@4" LIB hLibFI

DLL STATIC FUNCTION FIGETTAGKEY( nTag AS LONG ) AS LPSTR;
    PASCAL FROM "_FreeImage_GetTagKey@4" LIB hLibFI

DLL STATIC FUNCTION FICREATETAG() AS LONG;
    PASCAL FROM "_FreeImage_CreateTag@0" LIB hLibFI

DLL STATIC FUNCTION FIDELETETAG( nTag AS LONG ) AS VOID;
    PASCAL FROM "_FreeImage_DeleteTag@4" LIB hLibFI

DLL STATIC FUNCTION FISETTAGKEY( nTag AS LONG, cKey AS LPSTR ) AS BOOL;
    PASCAL FROM "_FreeImage_SetTagKey@8" LIB hLibFI

DLL STATIC FUNCTION FISETTAGLENGTH( nTag AS LONG, nLength AS DWORD ) AS BOOL;
    PASCAL FROM "_FreeImage_SetTagLength@8" LIB hLibFI

DLL STATIC FUNCTION FISETTAGCOUNT( nTag AS LONG, nCount AS DWORD ) AS BOOL;
    PASCAL FROM "_FreeImage_SetTagCount@8" LIB hLibFI

DLL STATIC FUNCTION FISETTAGTYPE( nTag AS LONG, nType AS LONG ) AS BOOL;
    PASCAL FROM "_FreeImage_SetTagType@8" LIB hLibFI

DLL STATIC FUNCTION FISETTAGVALUE( nTag AS LONG, cValue AS LPSTR ) AS BOOL;
    PASCAL FROM "_FreeImage_SetTagValue@8" LIB hLibFI

DLL STATIC FUNCTION FISETMETADATA( nModel AS LONG, hDib AS LONG, cKey AS LPSTR, nTag AS LONG ) AS BOOL;
    PASCAL FROM "_FreeImage_SetMetadata@16" LIB hLibFI

DLL STATIC FUNCTION FIUNLOAD( hDib AS LONG ) AS VOID;
    PASCAL FROM "_FreeImage_Unload@4" LIB hLibFI


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: JPG Meta Data

Postby nageswaragunupudi » Sun Aug 09, 2009 5:41 am

Mr Enrico

Thanks for the sample. This is very helpful
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 94 guests