[Gambas-user] Is exif Orientation obtainable without any exif libs/commands?

Martín Belmonte mbelmonte at belmotek.net
Wed Dec 7 00:18:30 CET 2022


El 5/12/22 a las 17:06, Bruce Steers escribió:
> Ultimately I'm looking to spin my images round to be correct way up 
> with zero quality change.
> The only piece of the puzzle gambas seems to lack is detecting the 
> exif Orientation flag.
> Something in my mind suspects gambas Read could possibly be able to 
> get the data from the files?

Hi Bruce, I made a gambas module, based on a sample from Italian Wiki, 
that extract all the info form one JPEG file.

Then the key (in the returned collection) called *orientation* has the 
info you looking for, please see the function *Exifdata*

To decrypt it here you are this:

http://jpegclub.org/exif_orientation.html

-----------------------------------------------------------------------------

Private content_count As Integer

Private ifd As Integer
Private entry_count As Integer
Private cData As New Collection

Library "libexif:12"

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

Private Extern exif_data_new_from_file(path As String) As ExifData
Private Extern exif_data_get_byte_order(data As ExifData) As Integer
Private Extern exif_byte_order_get_name(order As Integer) As String
Private Extern exif_data_foreach_content(data As ExifData, func As 
Pointer, user_data As Pointer)
Private Extern exif_content_foreach_entry(content As Pointer, func As 
Pointer, user_data As Pointer)
Private Extern exif_content_get_ifd(c As Pointer) As Integer
Private Extern exif_entry_get_value(entry As ExifEntry, _val As Pointer, 
maxlen As Integer) As String
Private Extern exif_tag_get_name_in_ifd(tag As Integer, ifd As Integer) 
As String
Private Extern exif_format_get_name(format_ As Integer) As String
Private Extern exif_data_unref(data As ExifData)

Public Function Exifdata(jpg As String) As Collection

   Dim ed As ExifData
   Dim callback_data As Pointer

   ed = exif_data_new_from_file(jpg)

   If IsNull(ed) Then Error.Raise("Errore !")
   exif_data_foreach_content(ed, data_foreach_func, callback_data)
   exif_data_unref(ed)

   Return cData

End

-----------------------------------------------------------------------------



More information about the User mailing list