Module: ExifGeoTag

Defined in:
lib/exif_geo_tag.rb,
lib/exif_geo_tag/version.rb,
ext/exif_geo_tag.c

Constant Summary collapse

VERSION =
'1.0.2'.freeze

Class Method Summary collapse

Class Method Details

.write_tag(file_path, new_values) ⇒ Object



922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
# File 'ext/exif_geo_tag.c', line 922

static VALUE egt_write_tag(VALUE self, VALUE file_path, VALUE new_values)
{
    ExifData *exif_data;
    ExifMem *mem;
    VALUE prev_values;
    (void)self;

    Check_Type(file_path, T_STRING);
    Check_Type(new_values, T_HASH);

    mem = exif_mem_new_default();
    exif_data = egt_exif_data_new_from_file(mem, RSTRING_PTR(file_path));
    if (!exif_data) {
        rb_raise(rb_eArgError, "file not readable or no EXIF data in file");
    }

    prev_values = rb_hash_new();

    egt_parse_virtual_fields(new_values);
#define X(e, i) egt_handle_tag(mem, exif_data, e, prev_values, new_values, egt_sym_##i);
    TAG_MAPPING(X)
#undef X
    egt_generate_virtual_fields(prev_values);

    if (rb_hash_size(new_values) > 0) {
        egt_save_exif_to_file(exif_data, RSTRING_PTR(file_path));
    }

    exif_data_free(exif_data);
    exif_mem_unref(mem);
    return prev_values;
}