ruby-exiv2 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/Makefile +143 -0
- data/lib/exif.cpp +116 -12
- data/lib/exiv2.cpp +11 -31
- data/lib/exiv2.hpp +4 -17
- data/lib/extconf.rb +2 -2
- data/lib/image.cpp +41 -11
- data/test/image.rb +34 -6
- metadata +16 -7
data/lib/Makefile
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
#### Start of system configuration section. ####
|
5
|
+
|
6
|
+
srcdir = .
|
7
|
+
topdir = /opt/local/lib/ruby/1.8/i686-darwin8.7.1
|
8
|
+
hdrdir = $(topdir)
|
9
|
+
VPATH = $(srcdir):$(topdir):$(hdrdir)
|
10
|
+
prefix = $(DESTDIR)/opt/local
|
11
|
+
exec_prefix = $(DESTDIR)/opt/local
|
12
|
+
sitedir = $(prefix)/lib/ruby/site_ruby
|
13
|
+
rubylibdir = $(libdir)/ruby/$(ruby_version)
|
14
|
+
archdir = $(rubylibdir)/$(arch)
|
15
|
+
sbindir = $(exec_prefix)/sbin
|
16
|
+
vendordir = $(prefix)/lib/ruby/vendor_ruby
|
17
|
+
datadir = $(prefix)/share
|
18
|
+
includedir = $(prefix)/include
|
19
|
+
infodir = $(prefix)/info
|
20
|
+
sysconfdir = $(prefix)/etc
|
21
|
+
mandir = $(DESTDIR)/opt/local/share/man
|
22
|
+
libdir = $(DESTDIR)/opt/local/lib
|
23
|
+
sharedstatedir = $(prefix)/com
|
24
|
+
oldincludedir = $(DESTDIR)/usr/include
|
25
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
26
|
+
vendorarchdir = $(vendorlibdir)/$(vendorarch)
|
27
|
+
bindir = $(exec_prefix)/bin
|
28
|
+
localstatedir = $(prefix)/var
|
29
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
30
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
31
|
+
libexecdir = $(exec_prefix)/libexec
|
32
|
+
|
33
|
+
CC = gcc
|
34
|
+
LIBRUBY = $(LIBRUBY_SO)
|
35
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
36
|
+
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
37
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
38
|
+
|
39
|
+
CFLAGS = -fno-common -O -pipe -I/opt/local/include -fno-common -pipe -fno-common
|
40
|
+
CPPFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir) -DHAVE_EXIF_HPP -O -pipe -I/opt/local/include -Wall -I/usr/local/include/exiv2 -I/usr/include/exiv2
|
41
|
+
CXXFLAGS = $(CFLAGS)
|
42
|
+
DLDFLAGS = -L/opt/local/lib -lstdc++
|
43
|
+
LDSHARED = g++ -g -dynamic -bundle -undefined suppress -flat_namespace
|
44
|
+
AR = ar
|
45
|
+
EXEEXT =
|
46
|
+
|
47
|
+
RUBY_INSTALL_NAME = ruby
|
48
|
+
RUBY_SO_NAME = ruby
|
49
|
+
arch = i686-darwin8.7.1
|
50
|
+
sitearch = i686-darwin8.7.1
|
51
|
+
vendorarch = i686-darwin8.7.1
|
52
|
+
ruby_version = 1.8
|
53
|
+
ruby = /opt/local/bin/ruby
|
54
|
+
RUBY = $(ruby)
|
55
|
+
RM = rm -f
|
56
|
+
MAKEDIRS = mkdir -p
|
57
|
+
INSTALL = /usr/bin/install -c
|
58
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
59
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
60
|
+
COPY = cp
|
61
|
+
|
62
|
+
#### End of system configuration section. ####
|
63
|
+
|
64
|
+
preload =
|
65
|
+
|
66
|
+
libpath = $(libdir)
|
67
|
+
LIBPATH = -L"$(libdir)"
|
68
|
+
DEFFILE =
|
69
|
+
|
70
|
+
CLEANFILES =
|
71
|
+
DISTCLEANFILES =
|
72
|
+
|
73
|
+
extout =
|
74
|
+
extout_prefix =
|
75
|
+
target_prefix =
|
76
|
+
LOCAL_LIBS =
|
77
|
+
LIBS = $(LIBRUBYARG_SHARED) -lexiv2 -lpthread -ldl -lobjc
|
78
|
+
SRCS = exif.cpp exiv2.cpp image.cpp
|
79
|
+
OBJS = exif.o exiv2.o image.o
|
80
|
+
TARGET = exiv2
|
81
|
+
DLLIB = $(TARGET).bundle
|
82
|
+
STATIC_LIB =
|
83
|
+
|
84
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
85
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
86
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
87
|
+
|
88
|
+
TARGET_SO = $(DLLIB)
|
89
|
+
CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
|
90
|
+
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
91
|
+
|
92
|
+
all: $(DLLIB)
|
93
|
+
static: $(STATIC_LIB)
|
94
|
+
|
95
|
+
clean:
|
96
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
97
|
+
|
98
|
+
distclean: clean
|
99
|
+
@-$(RM) Makefile extconf.h conftest.* mkmf.log
|
100
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
101
|
+
|
102
|
+
realclean: distclean
|
103
|
+
install: install-so install-rb
|
104
|
+
|
105
|
+
install-so: $(RUBYARCHDIR)
|
106
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
107
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
108
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
109
|
+
install-rb: pre-install-rb install-rb-default
|
110
|
+
install-rb-default: pre-install-rb-default
|
111
|
+
pre-install-rb: Makefile
|
112
|
+
pre-install-rb-default: Makefile
|
113
|
+
$(RUBYARCHDIR):
|
114
|
+
$(MAKEDIRS) $@
|
115
|
+
|
116
|
+
site-install: site-install-so site-install-rb
|
117
|
+
site-install-so: install-so
|
118
|
+
site-install-rb: install-rb
|
119
|
+
|
120
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
121
|
+
|
122
|
+
.cc.o:
|
123
|
+
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
|
124
|
+
|
125
|
+
.cxx.o:
|
126
|
+
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
|
127
|
+
|
128
|
+
.cpp.o:
|
129
|
+
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
|
130
|
+
|
131
|
+
.C.o:
|
132
|
+
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
|
133
|
+
|
134
|
+
.c.o:
|
135
|
+
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
|
136
|
+
|
137
|
+
$(DLLIB): $(OBJS)
|
138
|
+
@-$(RM) $@
|
139
|
+
$(LDSHARED) $(DLDFLAGS) $(LIBPATH) -o $@ $(OBJS) $(LOCAL_LIBS) $(LIBS)
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
$(OBJS): ruby.h defines.h
|
data/lib/exif.cpp
CHANGED
@@ -1,6 +1,77 @@
|
|
1
1
|
#include "exiv2.hpp"
|
2
2
|
|
3
|
-
|
3
|
+
|
4
|
+
static VALUE unmarshall_value(const Exiv2::Value& value) {
|
5
|
+
if(value.count() <= 0) {
|
6
|
+
rb_warn("Empty value (no entries)");
|
7
|
+
return Qnil;
|
8
|
+
}
|
9
|
+
|
10
|
+
Exiv2::TypeId type_id = value.typeId();
|
11
|
+
switch(type_id) {
|
12
|
+
case Exiv2::invalidTypeId:
|
13
|
+
{
|
14
|
+
rb_warn("Trying to demarshall invalid type id");
|
15
|
+
return Qnil;
|
16
|
+
}
|
17
|
+
|
18
|
+
case Exiv2::unsignedByte:
|
19
|
+
case Exiv2::unsignedShort:
|
20
|
+
case Exiv2::unsignedLong:
|
21
|
+
case Exiv2::signedShort:
|
22
|
+
case Exiv2::signedLong:
|
23
|
+
{
|
24
|
+
return INT2NUM(value.toLong());
|
25
|
+
}
|
26
|
+
|
27
|
+
case Exiv2::asciiString:
|
28
|
+
case Exiv2::string:
|
29
|
+
case Exiv2::undefined:
|
30
|
+
{
|
31
|
+
VALUE str = rb_str_buf_new(value.size() - 1);
|
32
|
+
value.copy((Exiv2::byte *)STR(str), Exiv2::littleEndian);
|
33
|
+
LEN(str) = value.size() - 1;
|
34
|
+
return str;
|
35
|
+
}
|
36
|
+
|
37
|
+
case Exiv2::unsignedRational:
|
38
|
+
case Exiv2::signedRational:
|
39
|
+
{
|
40
|
+
return rb_str_new2(value.toString().c_str());
|
41
|
+
Exiv2::Rational r = value.toRational();
|
42
|
+
ID rational_id = rb_intern("Rational");
|
43
|
+
if(0 && rb_const_defined(rb_cObject, rational_id)) {
|
44
|
+
VALUE rational = rb_const_get(rb_cObject, rational_id);
|
45
|
+
return rb_funcall(rational, rb_intern("new!"), 2, INT2NUM(r.first), INT2NUM(r.second));
|
46
|
+
}
|
47
|
+
return INT2NUM(r.first/r.second);
|
48
|
+
}
|
49
|
+
|
50
|
+
case Exiv2::invalid6:
|
51
|
+
case Exiv2::date:
|
52
|
+
case Exiv2::time:
|
53
|
+
case Exiv2::comment:
|
54
|
+
case Exiv2::directory:
|
55
|
+
case Exiv2::lastTypeId:
|
56
|
+
{
|
57
|
+
VALUE str = rb_str_buf_new(value.size() - 1);
|
58
|
+
value.copy((Exiv2::byte *)STR(str), Exiv2::littleEndian);
|
59
|
+
LEN(str) = value.size() - 1;
|
60
|
+
char msg[200];
|
61
|
+
snprintf(msg, sizeof(msg), " !!! %d", type_id);
|
62
|
+
rb_funcall(str, rb_intern("<<"), 1, rb_str_new2(msg));
|
63
|
+
return str;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
return Qfalse;
|
67
|
+
}
|
68
|
+
|
69
|
+
/*
|
70
|
+
* Access exif tag by name
|
71
|
+
*
|
72
|
+
* <code>Exiv2::Image.new("a.jpg").exif["Exif.Image.Model"] => "FinePixS2Pro"</code>
|
73
|
+
*/
|
74
|
+
static VALUE exiv2_exif_get(VALUE self, VALUE key) {
|
4
75
|
__BEGIN
|
5
76
|
rbImage* image;
|
6
77
|
Data_Get_Struct(self, rbImage, image);
|
@@ -18,12 +89,17 @@ VALUE exiv2_exif_get(VALUE self, VALUE key) {
|
|
18
89
|
return Qnil;
|
19
90
|
}
|
20
91
|
|
21
|
-
|
22
|
-
|
92
|
+
return unmarshall_value(pos->value());
|
93
|
+
//std::string v = pos->toString();
|
94
|
+
//return rb_str_new(v.c_str(), v.length());
|
23
95
|
__NIL_END
|
24
96
|
}
|
25
97
|
|
26
|
-
|
98
|
+
/*
|
99
|
+
* @exif["Exif.Photo.PixelXDimension"] = 3024
|
100
|
+
* [] — is a universal accessor
|
101
|
+
*/
|
102
|
+
static VALUE exiv2_exif_set(VALUE self, VALUE key, VALUE value) {
|
27
103
|
__BEGIN
|
28
104
|
rbImage* image;
|
29
105
|
Data_Get_Struct(self, rbImage, image);
|
@@ -38,7 +114,10 @@ VALUE exiv2_exif_set(VALUE self, VALUE key, VALUE value) {
|
|
38
114
|
__NIL_END
|
39
115
|
}
|
40
116
|
|
41
|
-
|
117
|
+
/*
|
118
|
+
* Iterates through all exif tags in image
|
119
|
+
*/
|
120
|
+
static VALUE exiv2_exif_each(int argc, VALUE *argv, VALUE self) {
|
42
121
|
__BEGIN
|
43
122
|
rbImage* image;
|
44
123
|
Data_Get_Struct(self, rbImage, image);
|
@@ -54,7 +133,8 @@ VALUE exiv2_exif_each(int argc, VALUE *argv, VALUE self) {
|
|
54
133
|
Exiv2::ExifData::const_iterator end = exifData.end();
|
55
134
|
for(Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) {
|
56
135
|
VALUE key = rb_str_new(i->key().c_str(), i->key().length());
|
57
|
-
VALUE val =
|
136
|
+
VALUE val = unmarshall_value(i->value());
|
137
|
+
//VALUE val = rb_str_new(i->toString().c_str(), i->toString().length());
|
58
138
|
if(prefix != Qnil && INT2FIX(0) != rb_funcall(key, rb_intern("index"), 1, prefix)) {
|
59
139
|
continue;
|
60
140
|
}
|
@@ -64,7 +144,10 @@ VALUE exiv2_exif_each(int argc, VALUE *argv, VALUE self) {
|
|
64
144
|
__END
|
65
145
|
}
|
66
146
|
|
67
|
-
|
147
|
+
/*
|
148
|
+
* Delete exif value by it's name
|
149
|
+
*/
|
150
|
+
static VALUE exiv2_exif_delete(VALUE self, VALUE key) {
|
68
151
|
__BEGIN
|
69
152
|
rbImage* image;
|
70
153
|
Data_Get_Struct(self, rbImage, image);
|
@@ -77,7 +160,7 @@ VALUE exiv2_exif_delete(VALUE self, VALUE key) {
|
|
77
160
|
}
|
78
161
|
|
79
162
|
Exiv2::ExifKey exifKey(STR(strkey));
|
80
|
-
Exiv2::ExifData::
|
163
|
+
Exiv2::ExifData::iterator pos = exifData.findKey(exifKey);
|
81
164
|
if (pos == exifData.end()) {
|
82
165
|
return Qnil;
|
83
166
|
}
|
@@ -88,7 +171,10 @@ VALUE exiv2_exif_delete(VALUE self, VALUE key) {
|
|
88
171
|
__NIL_END
|
89
172
|
}
|
90
173
|
|
91
|
-
|
174
|
+
/*
|
175
|
+
* Clear all exif data in image
|
176
|
+
*/
|
177
|
+
static VALUE exiv2_exif_clear(VALUE self) {
|
92
178
|
__BEGIN
|
93
179
|
rbImage* image;
|
94
180
|
Data_Get_Struct(self, rbImage, image);
|
@@ -103,8 +189,10 @@ VALUE exiv2_exif_clear(VALUE self) {
|
|
103
189
|
__END
|
104
190
|
}
|
105
191
|
|
106
|
-
|
107
|
-
|
192
|
+
/*
|
193
|
+
* Count of exif tags in image
|
194
|
+
*/
|
195
|
+
static VALUE exiv2_exif_count(VALUE self) {
|
108
196
|
__BEGIN
|
109
197
|
rbImage* image;
|
110
198
|
Data_Get_Struct(self, rbImage, image);
|
@@ -115,7 +203,10 @@ VALUE exiv2_exif_count(VALUE self) {
|
|
115
203
|
__END
|
116
204
|
}
|
117
205
|
|
118
|
-
|
206
|
+
/*
|
207
|
+
* Predicate method. Is exif empty?
|
208
|
+
*/
|
209
|
+
static VALUE exiv2_exif_empty(VALUE self) {
|
119
210
|
__BEGIN
|
120
211
|
rbImage* image;
|
121
212
|
Data_Get_Struct(self, rbImage, image);
|
@@ -124,4 +215,17 @@ VALUE exiv2_exif_empty(VALUE self) {
|
|
124
215
|
|
125
216
|
return exifData.empty() ? Qtrue : Qfalse;
|
126
217
|
__NIL_END
|
218
|
+
}
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
void Init_exif() {
|
223
|
+
cExif = rb_define_class_under(mExiv2, "Exif", rb_cObject);
|
224
|
+
rb_define_method(cExif, "each", VALUEFUNC(exiv2_exif_each), -1);
|
225
|
+
rb_define_method(cExif, "[]", VALUEFUNC(exiv2_exif_get), 1);
|
226
|
+
rb_define_method(cExif, "[]=", VALUEFUNC(exiv2_exif_set), 2);
|
227
|
+
rb_define_method(cExif, "delete", VALUEFUNC(exiv2_exif_delete), 1);
|
228
|
+
rb_define_method(cExif, "clear", VALUEFUNC(exiv2_exif_clear), 0);
|
229
|
+
rb_define_method(cExif, "count", VALUEFUNC(exiv2_exif_count), 0);
|
230
|
+
rb_define_method(cExif, "empty?", VALUEFUNC(exiv2_exif_empty), 0);
|
127
231
|
}
|
data/lib/exiv2.cpp
CHANGED
@@ -29,7 +29,7 @@
|
|
29
29
|
#include "exiv2.hpp"
|
30
30
|
|
31
31
|
|
32
|
-
VALUE mExiv2, cImage, cExif, cIptc, cThumbnail;
|
32
|
+
VALUE mExiv2, cImage, cExif, cIptc, cThumbnail, eError;
|
33
33
|
|
34
34
|
#ifdef __cplusplus
|
35
35
|
extern "C"
|
@@ -39,35 +39,15 @@ extern "C"
|
|
39
39
|
void Init_exiv2() {
|
40
40
|
mExiv2 = rb_define_module("Exiv2");
|
41
41
|
|
42
|
-
|
43
|
-
rb_define_alloc_func(cImage, exiv2_image_s_allocate);
|
44
|
-
rb_define_method(cImage, "initialize", VALUEFUNC(exiv2_image_initialize), 1);
|
45
|
-
rb_define_method(cImage, "exif", VALUEFUNC(exiv2_image_exif), 0);
|
46
|
-
/*
|
47
|
-
rb_define_method(cImage, "thumbnail", VALUEFUNC(exiv2_image_thumbnail), 0);
|
48
|
-
rb_define_method(cImage, "thumbnail=", VALUEFUNC(exiv2_image_thumbnail_set), 0);
|
49
|
-
*/
|
50
|
-
rb_define_method(cImage, "save", VALUEFUNC(exiv2_image_save), 0);
|
51
|
-
rb_define_method(cImage, "clear", VALUEFUNC(exiv2_image_clear), 0);
|
52
|
-
rb_define_method(cImage, "comment", VALUEFUNC(exiv2_image_get_comment), 0);
|
53
|
-
rb_define_method(cImage, "comment=", VALUEFUNC(exiv2_image_set_comment), 1);
|
42
|
+
eError = rb_define_class_under(mExiv2, "Error", rb_eStandardError);
|
54
43
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
rb_define_method(
|
59
|
-
rb_define_method(
|
60
|
-
rb_define_method(
|
61
|
-
rb_define_method(
|
62
|
-
rb_define_method(
|
63
|
-
|
64
|
-
/*
|
65
|
-
cThumbnail = rb_define_class_under(mExiv2, "Thumbnail", rb_cObject);
|
66
|
-
rb_define_method(cThumbnail, "extension", VALUEFUNC(exiv2_thumb_ext), 0);
|
67
|
-
rb_define_method(cThumbnail, "format", VALUEFUNC(exiv2_thumb_format), 0);
|
68
|
-
rb_define_method(cThumbnail, "clear", VALUEFUNC(exiv2_thumb_clear), 0);
|
69
|
-
rb_define_method(cThumbnail, "to_s", VALUEFUNC(exiv2_thumb_read), 0);
|
70
|
-
rb_define_method(cThumbnail, "read", VALUEFUNC(exiv2_thumb_read), 0);
|
71
|
-
rb_define_method(cThumbnail, "write", VALUEFUNC(exiv2_thumb_write), 1);
|
72
|
-
*/
|
44
|
+
Init_image();
|
45
|
+
Init_exif();
|
46
|
+
//cThumbnail = rb_define_class_under(mExiv2, "Thumbnail", rb_cObject);
|
47
|
+
//rb_define_method(cThumbnail, "extension", VALUEFUNC(exiv2_thumb_ext), 0);
|
48
|
+
//rb_define_method(cThumbnail, "format", VALUEFUNC(exiv2_thumb_format), 0);
|
49
|
+
//rb_define_method(cThumbnail, "clear", VALUEFUNC(exiv2_thumb_clear), 0);
|
50
|
+
//rb_define_method(cThumbnail, "to_s", VALUEFUNC(exiv2_thumb_read), 0);
|
51
|
+
//rb_define_method(cThumbnail, "read", VALUEFUNC(exiv2_thumb_read), 0);
|
52
|
+
//rb_define_method(cThumbnail, "write", VALUEFUNC(exiv2_thumb_write), 1);
|
73
53
|
}
|
data/lib/exiv2.hpp
CHANGED
@@ -77,7 +77,7 @@
|
|
77
77
|
#define RUN(x) if(!x) { return Qnil; }
|
78
78
|
|
79
79
|
#define __BEGIN try {
|
80
|
-
#define __END } catch(Exiv2::AnyError& e) { rb_raise(
|
80
|
+
#define __END } catch(Exiv2::AnyError& e) { rb_raise(eError, "Error occured in exiv2 library: %s", e.what().c_str());}
|
81
81
|
#define __NIL_END } catch(Exiv2::AnyError& e) { return Qnil; }
|
82
82
|
#define __VOID_END } catch(Exiv2::AnyError& e) {}
|
83
83
|
|
@@ -85,7 +85,7 @@
|
|
85
85
|
extern "C" {
|
86
86
|
#endif
|
87
87
|
void Init_exiv2(void);
|
88
|
-
extern VALUE mExiv2, cImage, cExif, cIptc;
|
88
|
+
extern VALUE mExiv2, cImage, cExif, cIptc, eError;
|
89
89
|
|
90
90
|
#if defined(__cplusplus)
|
91
91
|
} /* extern "C" { */
|
@@ -98,21 +98,8 @@ struct rbImage {
|
|
98
98
|
};
|
99
99
|
|
100
100
|
|
101
|
-
|
102
|
-
|
103
|
-
VALUE exiv2_image_save(VALUE self);
|
104
|
-
VALUE exiv2_image_clear(VALUE self);
|
105
|
-
VALUE exiv2_image_exif(VALUE self);
|
106
|
-
VALUE exiv2_image_get_comment(VALUE self);
|
107
|
-
VALUE exiv2_image_set_comment(VALUE self, VALUE comment);
|
108
|
-
|
109
|
-
VALUE exiv2_exif_get(VALUE self, VALUE key);
|
110
|
-
VALUE exiv2_exif_set(VALUE self, VALUE key, VALUE value);
|
111
|
-
VALUE exiv2_exif_each(int argc, VALUE *argv, VALUE self);
|
112
|
-
VALUE exiv2_exif_delete(VALUE self, VALUE key);
|
113
|
-
VALUE exiv2_exif_size(VALUE self);
|
114
|
-
VALUE exiv2_exif_empty(VALUE self);
|
115
|
-
VALUE exiv2_exif_clear(VALUE self);
|
101
|
+
void Init_image();
|
102
|
+
void Init_exif();
|
116
103
|
|
117
104
|
|
118
105
|
#endif /* EXIV2_HPP_ */
|
data/lib/extconf.rb
CHANGED
@@ -6,8 +6,8 @@ CONFIG['LDSHARED'] = "g++ -g -dynamic -bundle -undefined suppress -flat_namespa
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
$CPPFLAGS << " -Wall -I/usr/local/include/exiv2 "
|
10
|
-
$LDFLAGS << " -lstdc++
|
9
|
+
$CPPFLAGS << " -Wall -I/usr/local/include/exiv2 -I/usr/include/exiv2 "
|
10
|
+
$LDFLAGS << " -lstdc++ "
|
11
11
|
have_header "exif.hpp"
|
12
12
|
have_library "exiv2", "_ZN5Exiv29MetadatumD0Ev"
|
13
13
|
create_makefile 'exiv2'
|
data/lib/image.cpp
CHANGED
@@ -13,7 +13,7 @@ static void image_leave(rbImage* image) {
|
|
13
13
|
|
14
14
|
}
|
15
15
|
|
16
|
-
VALUE exiv2_image_s_allocate(VALUE klass) {
|
16
|
+
static VALUE exiv2_image_s_allocate(VALUE klass) {
|
17
17
|
__BEGIN
|
18
18
|
rbImage* image = new rbImage();
|
19
19
|
image->dirty = false;
|
@@ -21,7 +21,11 @@ VALUE exiv2_image_s_allocate(VALUE klass) {
|
|
21
21
|
__END
|
22
22
|
}
|
23
23
|
|
24
|
-
|
24
|
+
/*
|
25
|
+
* img = Exiv2::Image.new("IMGP3025.jpg")
|
26
|
+
* => #<Exiv2::Image:0x844bc>
|
27
|
+
*/
|
28
|
+
static VALUE exiv2_image_initialize(VALUE self, VALUE file) {
|
25
29
|
__BEGIN
|
26
30
|
rbImage* image;
|
27
31
|
Data_Get_Struct(self, rbImage, image);
|
@@ -30,7 +34,7 @@ VALUE exiv2_image_initialize(VALUE self, VALUE file) {
|
|
30
34
|
try {
|
31
35
|
if(rb_respond_to(file, rb_intern("read"))) {
|
32
36
|
VALUE file_content = rb_funcall(file, rb_intern("read"), 0);
|
33
|
-
rb_iv_set(self, "file_content", file_content);
|
37
|
+
rb_iv_set(self, "@file_content", file_content);
|
34
38
|
image->image = Exiv2::ImageFactory::open(CBSTR(file_content), LEN(file_content));
|
35
39
|
} else if(TYPE(file) == T_STRING) {
|
36
40
|
image->image = Exiv2::ImageFactory::open(CSTR(file));
|
@@ -52,7 +56,10 @@ static void image_real_save(rbImage* image) {
|
|
52
56
|
}
|
53
57
|
}
|
54
58
|
|
55
|
-
|
59
|
+
/*
|
60
|
+
* Save image with changed data
|
61
|
+
*/
|
62
|
+
static VALUE exiv2_image_save(VALUE self) {
|
56
63
|
__BEGIN
|
57
64
|
rbImage* image;
|
58
65
|
Data_Get_Struct(self, rbImage, image);
|
@@ -61,8 +68,10 @@ VALUE exiv2_image_save(VALUE self) {
|
|
61
68
|
__END
|
62
69
|
}
|
63
70
|
|
64
|
-
|
65
|
-
|
71
|
+
/*
|
72
|
+
* Clear all metadata in image. Not only exif
|
73
|
+
*/
|
74
|
+
static VALUE exiv2_image_clear(VALUE self) {
|
66
75
|
__BEGIN
|
67
76
|
rbImage* image;
|
68
77
|
Data_Get_Struct(self, rbImage, image);
|
@@ -72,8 +81,10 @@ VALUE exiv2_image_clear(VALUE self) {
|
|
72
81
|
__END
|
73
82
|
}
|
74
83
|
|
75
|
-
|
76
|
-
|
84
|
+
/*
|
85
|
+
* Get comment of image
|
86
|
+
*/
|
87
|
+
static VALUE exiv2_image_get_comment(VALUE self) {
|
77
88
|
__BEGIN
|
78
89
|
rbImage* image;
|
79
90
|
Data_Get_Struct(self, rbImage, image);
|
@@ -82,7 +93,10 @@ VALUE exiv2_image_get_comment(VALUE self) {
|
|
82
93
|
__END
|
83
94
|
}
|
84
95
|
|
85
|
-
|
96
|
+
/*
|
97
|
+
* Set comment in image
|
98
|
+
*/
|
99
|
+
static VALUE exiv2_image_set_comment(VALUE self, VALUE comment) {
|
86
100
|
__BEGIN
|
87
101
|
rbImage* image;
|
88
102
|
Data_Get_Struct(self, rbImage, image);
|
@@ -105,8 +119,10 @@ VALUE exiv2_image_set_comment(VALUE self, VALUE comment) {
|
|
105
119
|
__END
|
106
120
|
}
|
107
121
|
|
108
|
-
|
109
|
-
|
122
|
+
/*
|
123
|
+
* Access to exif data of image
|
124
|
+
*/
|
125
|
+
static VALUE exiv2_image_exif(VALUE self) {
|
110
126
|
__BEGIN
|
111
127
|
rbImage* image;
|
112
128
|
Data_Get_Struct(self, rbImage, image);
|
@@ -116,3 +132,17 @@ VALUE exiv2_image_exif(VALUE self) {
|
|
116
132
|
__END
|
117
133
|
}
|
118
134
|
|
135
|
+
void Init_image() {
|
136
|
+
cImage = rb_define_class_under(mExiv2, "Image", rb_cObject);
|
137
|
+
rb_define_alloc_func(cImage, exiv2_image_s_allocate);
|
138
|
+
rb_define_method(cImage, "initialize", VALUEFUNC(exiv2_image_initialize), 1);
|
139
|
+
rb_define_method(cImage, "exif", VALUEFUNC(exiv2_image_exif), 0);
|
140
|
+
|
141
|
+
//rb_define_method(cImage, "thumbnail", VALUEFUNC(exiv2_image_thumbnail), 0);
|
142
|
+
//rb_define_method(cImage, "thumbnail=", VALUEFUNC(exiv2_image_thumbnail_set), 0);
|
143
|
+
|
144
|
+
rb_define_method(cImage, "save", VALUEFUNC(exiv2_image_save), 0);
|
145
|
+
rb_define_method(cImage, "clear", VALUEFUNC(exiv2_image_clear), 0);
|
146
|
+
rb_define_method(cImage, "comment", VALUEFUNC(exiv2_image_get_comment), 0);
|
147
|
+
rb_define_method(cImage, "comment=", VALUEFUNC(exiv2_image_set_comment), 1);
|
148
|
+
}
|
data/test/image.rb
CHANGED
@@ -2,9 +2,10 @@ require 'test/unit'
|
|
2
2
|
require File.dirname(__FILE__) + '/../lib/exiv2'
|
3
3
|
require 'tempfile'
|
4
4
|
|
5
|
+
|
5
6
|
class ImageTest < Test::Unit::TestCase
|
6
7
|
|
7
|
-
def
|
8
|
+
def open_test_file(filename)
|
8
9
|
test_file_name = File.dirname(__FILE__) + "/data/file_test"
|
9
10
|
open(test_file_name, "w+") do |f|
|
10
11
|
open(File.dirname(__FILE__) + "/data/#{filename}") do |real|
|
@@ -19,8 +20,15 @@ class ImageTest < Test::Unit::TestCase
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def test_open
|
22
|
-
|
23
|
-
assert @img = Exiv2::Image.new(f)
|
23
|
+
open_test_file "exiv2-fujifilm-finepix-s2pro.jpg" do |f|
|
24
|
+
assert @img = Exiv2::Image.new(f), "Image should be opened from IO::File"
|
25
|
+
assert_equal "FinePixS2Pro", @img.exif["Exif.Image.Model"]
|
26
|
+
assert_equal nil, @img.exif["zeze"]
|
27
|
+
assert_equal "3024", @img.exif["Exif.Photo.PixelXDimension"]
|
28
|
+
end
|
29
|
+
|
30
|
+
open_test_file "exiv2-fujifilm-finepix-s2pro.jpg" do |f|
|
31
|
+
assert @img = Exiv2::Image.new(f.path), "Image should be opened from filename"
|
24
32
|
assert_equal "FinePixS2Pro", @img.exif["Exif.Image.Model"]
|
25
33
|
assert_equal nil, @img.exif["zeze"]
|
26
34
|
assert_equal "3024", @img.exif["Exif.Photo.PixelXDimension"]
|
@@ -28,8 +36,9 @@ class ImageTest < Test::Unit::TestCase
|
|
28
36
|
end
|
29
37
|
|
30
38
|
def test_write
|
31
|
-
|
39
|
+
open_test_file "exiv2-fujifilm-finepix-s2pro.jpg" do |f|
|
32
40
|
assert @img = Exiv2::Image.new(f)
|
41
|
+
assert_equal "FinePixS2Pro", @img.exif["Exif.Image.Model"]
|
33
42
|
assert_equal "*istDs", @img.exif["Exif.Image.Model"] = "*istDs"
|
34
43
|
assert @img.save
|
35
44
|
|
@@ -39,7 +48,7 @@ class ImageTest < Test::Unit::TestCase
|
|
39
48
|
end
|
40
49
|
|
41
50
|
def test_comment
|
42
|
-
|
51
|
+
open_test_file "exiv2-fujifilm-finepix-s2pro.jpg" do |f|
|
43
52
|
assert @img = Exiv2::Image.new(f)
|
44
53
|
assert_equal "My funny comment", @img.comment = "My funny comment"
|
45
54
|
assert @img.save
|
@@ -48,13 +57,32 @@ class ImageTest < Test::Unit::TestCase
|
|
48
57
|
assert_equal "My funny comment", @img.comment
|
49
58
|
end
|
50
59
|
end
|
60
|
+
|
61
|
+
def test_typehinting
|
62
|
+
open_test_file "exiv2-fujifilm-finepix-s2pro.jpg" do |f|
|
63
|
+
assert @img = Exiv2::Image.new(f)
|
64
|
+
assert @exif = @img.exif
|
65
|
+
assert_equal 1, @exif["Exif.Image.Orientation"]
|
66
|
+
assert_equal "Digital Camera FinePixS2Pro Ver1.00", @exif["Exif.Image.Software"]
|
67
|
+
assert_equal 72, @exif["Exif.Image.XResolution"]
|
68
|
+
assert_equal String, @exif["Exif.Image.XResolution"].class
|
69
|
+
puts @exif["Exif.Image.XResolution"].class
|
70
|
+
|
71
|
+
require 'rational'
|
72
|
+
|
73
|
+
assert_equal 72, @exif["Exif.Image.XResolution"]
|
74
|
+
assert_equal Numeric, @exif["Exif.Image.XResolution"].class
|
75
|
+
puts @exif["Exif.Image.XResolution"].class
|
76
|
+
end
|
77
|
+
end
|
51
78
|
|
52
79
|
def test_each
|
53
|
-
|
80
|
+
open_test_file "exiv2-fujifilm-finepix-s2pro.jpg" do |f|
|
54
81
|
assert @img = Exiv2::Image.new(f)
|
55
82
|
i = 0
|
56
83
|
@img.exif.each do |key, value|
|
57
84
|
i = i + 1
|
85
|
+
#puts "#{key} => #{value.inspect}"
|
58
86
|
assert key
|
59
87
|
assert value
|
60
88
|
end
|
metadata
CHANGED
@@ -3,13 +3,13 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-exiv2
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "0.
|
7
|
-
date: 2006-
|
8
|
-
summary: Exiv2 library
|
6
|
+
version: "0.2"
|
7
|
+
date: 2006-10-30 00:00:00 +03:00
|
8
|
+
summary: Exiv2 (exif image tags handling) library driver
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: max@maxidoors.ru
|
12
|
-
homepage: http://
|
12
|
+
homepage: http://maxidoors.ru/
|
13
13
|
rubyforge_project: ruby-exiv2
|
14
14
|
description:
|
15
15
|
autorequire: intersys
|
@@ -36,13 +36,14 @@ files:
|
|
36
36
|
- lib/exiv2.hpp
|
37
37
|
- lib/extconf.rb
|
38
38
|
- lib/image.cpp
|
39
|
+
- lib/Makefile
|
39
40
|
- README
|
40
41
|
test_files: []
|
41
42
|
|
42
43
|
rdoc_options:
|
43
44
|
- --main=README
|
44
45
|
- --line-numbers
|
45
|
-
- --webcvs=svn
|
46
|
+
- --webcvs=http://svn.maxidoors.ru/ruby-exiv2
|
46
47
|
- --charset=utf-8
|
47
48
|
- --promiscuous
|
48
49
|
extra_rdoc_files:
|
@@ -53,5 +54,13 @@ extensions:
|
|
53
54
|
- lib/extconf.rb
|
54
55
|
requirements: []
|
55
56
|
|
56
|
-
dependencies:
|
57
|
-
|
57
|
+
dependencies:
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: activesupport
|
60
|
+
version_requirement:
|
61
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "1.0"
|
66
|
+
version:
|