Differenze tra le versioni di "Ottenere Metadati Exif da un'immagine JPEG con le risorse del API di libexif"

Da Gambas-it.org - Wikipedia.
(Creata pagina con "Il formato di file JPEG consente di incorporare informazioni aggiuntive chiamate "metadati" nell'intestazione del file. Lo scopo di questi metadati è di fornire informazioni...")
 
 
Riga 3: Riga 3:
 
E' possibile estrarre tali Metadati, eventualmente contenuti in un file immagine JPEG usando le risorse della libreria ''Libexif''.
 
E' possibile estrarre tali Metadati, eventualmente contenuti in un file immagine JPEG usando le risorse della libreria ''Libexif''.
  
E' necessario avere installata nel sistemae richiamare in gambas la seguente libreria condivisa: "''libexif.so.12.3.3''"
+
E' necessario avere installata nel sistemae richiamare in gambas la seguente libreria condivisa: "''libexif.so.12.3.4'' ".
  
  
Riga 12: Riga 12:
 
   
 
   
 
   
 
   
  Library "libexif:12.3.3"
+
  Library "libexif:12.3.4"
 
   
 
   
 
  Public Struct ExifData
 
  Public Struct ExifData
Riga 71: Riga 71:
 
   
 
   
 
   
 
   
  '''Public''' Sub Main()
+
  Public Sub Main()
 
    
 
    
 
   Dim ed As ExifData
 
   Dim ed As ExifData
Riga 77: Riga 77:
 
   Dim callback_data As Pointer
 
   Dim callback_data As Pointer
 
    
 
    
   jpg = "<FONT Color=gray>''/percorso/del/file.jpg''</font>"
+
   jpg = "<FONT Color=darkgreen>''/percorso/del/file.jpg''</font>"
 
   Print "File immagine:  "; jpg
 
   Print "File immagine:  "; jpg
 
    
 
    
Riga 88: Riga 88:
 
    
 
    
 
   exif_data_unref(ed)
 
   exif_data_unref(ed)
 
+
  '''End'''
+
  End
 
   
 
   
 
   
 
   
  '''Private''' Function data_foreach_func(content As Pointer, callback_data As Pointer)
+
  Private Function data_foreach_func(content As Pointer, callback_data As Pointer)
 
    
 
    
 
   ifd = exif_content_get_ifd(content)
 
   ifd = exif_content_get_ifd(content)
Riga 101: Riga 101:
 
   Inc content_count
 
   Inc content_count
 
    
 
    
'''End'''
+
End
 
   
 
   
 
   
 
   
  '''Private''' Function content_foreach_func(entry As Pointer, callback_data As Pointer)
+
  Private Function content_foreach_func(entry As Pointer, callback_data As Pointer)
 
    
 
    
 
   Dim buf As New Byte[2000]
 
   Dim buf As New Byte[2000]
Riga 118: Riga 118:
 
   Inc entry_count
 
   Inc entry_count
 
    
 
    
  '''End'''
+
  End
  
  

Versione attuale delle 15:33, 3 lug 2024

Il formato di file JPEG consente di incorporare informazioni aggiuntive chiamate "metadati" nell'intestazione del file. Lo scopo di questi metadati è di fornire informazioni aggiuntive e utili insieme all'immagine.

E' possibile estrarre tali Metadati, eventualmente contenuti in un file immagine JPEG usando le risorse della libreria Libexif.

E' necessario avere installata nel sistemae richiamare in gambas la seguente libreria condivisa: "libexif.so.12.3.4 ".


Mostriamo un semplice esempio:

Private content_count As Integer
Private ifd As Integer
Private entry_count As Integer


Library "libexif:12.3.4"

Public Struct ExifData
  ifd[5] As Pointer
  data As Pointer
  size As Integer
  priv As Pointer
End Struct

Public Struct ExifEntry
  tag As Integer
  format_ As Integer
  components As Long
  data As Pointer
  size As Integer
  parent As Pointer
  priv As Pointer
End Struct

' ExifData *exif_data_new_from_file (const char *path)
' Allocate a new #Pointer and load EXIF data from a JPEG file.
Private Extern exif_data_new_from_file(path As String) As ExifData

' ExifByteOrder exif_data_get_byte_order  (ExifData *data)
' Return the byte order in use by this EXIF structure.
Private Extern exif_data_get_byte_order(data As ExifData) As Integer

' const char *exif_byte_order_get_name (ExifByteOrder order)
' Return a short, localized, textual name for the given byte order.
Private Extern exif_byte_order_get_name(order As Integer) As String

' void exif_data_foreach_content (ExifData *data, PointerForeachContentFunc func, void *user_data)
' Execute a function on each IFD in turn.
Private Extern exif_data_foreach_content(data As ExifData, func As Pointer, user_data As Pointer)

' void exif_content_foreach_entry (ExifContent *content, ExifContentForeachEntryFunc func, void *user_data)
' Executes function on each EXIF tag in this IFD in turn.
Private Extern exif_content_foreach_entry(content As Pointer, func As Pointer, user_data As Pointer)

' ExifIfd exif_content_get_ifd (ExifContent *c)
' Return the IFD number in which the given #ExifContent is found.
Private Extern exif_content_get_ifd(c As Pointer) As Integer

' const char *exif_entry_get_value (ExifEntry *entry, char *val, unsigned int maxlen)
' Return a localized textual representation of the value of the EXIF entry.
Private Extern exif_entry_get_value(entry As ExifEntry, _val As Pointer, maxlen As Integer) As String

' const char *exif_tag_get_name_in_ifd(ExifTag tag, ExifIfd ifd)
' Return a textual name of the given tag when found in the given IFD.
Private Extern exif_tag_get_name_in_ifd(tag As Integer, ifd As Integer) As String

' const char *exif_format_get_name (ExifFormat format)
' Return a textual representation of the given EXIF data type.
Private Extern exif_format_get_name(format_ As Integer) As String

' void exif_data_unref (ExifData *data)
Private Extern exif_data_unref(data As ExifData)


Public Sub Main()
 
 Dim ed As ExifData
 Dim jpg As String
 Dim callback_data As Pointer
 
 jpg = "/percorso/del/file.jpg"
 Print "File immagine:   "; jpg
 
 ed = exif_data_new_from_file(jpg)
 If IsNull(ed) Then Error.Raise("Errore !")
 
 Print "Ordine dei byte: "; exif_byte_order_get_name(exif_data_get_byte_order(ed))
 
 exif_data_foreach_content(ed, data_foreach_func, callback_data)
 
 exif_data_unref(ed)

End


Private Function data_foreach_func(content As Pointer, callback_data As Pointer)
 
 ifd = exif_content_get_ifd(content)
 Print "  Content :"; content_count, "ifd= "; ifd
 
 exif_content_foreach_entry(content, content_foreach_func, callback_data)
 
 Inc content_count
  
End


Private Function content_foreach_func(entry As Pointer, callback_data As Pointer)
 
 Dim buf As New Byte[2000]
 Dim ent As ExifEntry
 
 ent = entry
 
 exif_entry_get_value(entry, buf.Data, buf.Count)
 
 Print "   Entry"; entry_count; ": "; exif_tag_get_name_in_ifd(ent.tag, ifd); "("; exif_format_get_name(ent.format_); ")"
 Print "      Size, Comps: "; ent.size; ", "; ent.components
 Print "      Value: "; exif_entry_get_value(ent, buf.Data, buf.Count)
 Inc entry_count
 
End


Riferimenti