exiv2 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +4 -0
- data/ext/exiv2/exiv2.cpp +23 -1
- data/lib/exiv2/version.rb +1 -1
- data/lib/exiv2/xmp_data.rb +22 -0
- data/lib/exiv2.rb +1 -0
- data/spec/exiv2_spec.rb +27 -0
- data/spec/files/test.jpg +0 -0
- metadata +7 -6
data/README.rdoc
CHANGED
@@ -17,6 +17,10 @@ Requires that the exiv2 C++ library is installed.
|
|
17
17
|
puts "#{key} = #{value}\n"
|
18
18
|
end
|
19
19
|
image.exif_data.each { ... }
|
20
|
+
image.xmp_data.each { ... }
|
21
|
+
|
22
|
+
iptc_data_hash = image.iptc_data.to_hash
|
23
|
+
xmp_data_hash = image.xmp_data.to_hash
|
20
24
|
|
21
25
|
== Why?
|
22
26
|
|
data/ext/exiv2/exiv2.cpp
CHANGED
@@ -12,7 +12,7 @@ static std::string to_std_string(VALUE string) {
|
|
12
12
|
return std::string(RSTRING(string)->ptr, RSTRING(string)->len);
|
13
13
|
}
|
14
14
|
|
15
|
-
// Shared method for implementing each on IptcData and ExifData.
|
15
|
+
// Shared method for implementing each on XmpData, IptcData and ExifData.
|
16
16
|
template <class T>
|
17
17
|
static VALUE metadata_each(VALUE self) {
|
18
18
|
T* data;
|
@@ -39,6 +39,7 @@ extern "C" {
|
|
39
39
|
static void image_free(Exiv2::Image* image);
|
40
40
|
static VALUE image_read_metadata(VALUE self);
|
41
41
|
static VALUE image_iptc_data(VALUE self);
|
42
|
+
static VALUE image_xmp_data(VALUE self);
|
42
43
|
static VALUE image_exif_data(VALUE self);
|
43
44
|
|
44
45
|
static VALUE image_factory_class;
|
@@ -50,6 +51,8 @@ extern "C" {
|
|
50
51
|
static VALUE iptc_data_class;
|
51
52
|
static VALUE iptc_data_each(VALUE self);
|
52
53
|
|
54
|
+
static VALUE xmp_data_class;
|
55
|
+
static VALUE xmp_data_each(VALUE self);
|
53
56
|
|
54
57
|
void Init_exiv2() {
|
55
58
|
VALUE enumerable_module = rb_const_get(rb_cObject, rb_intern("Enumerable"));
|
@@ -61,6 +64,7 @@ extern "C" {
|
|
61
64
|
image_class = rb_define_class_under(exiv2_module, "Image", rb_cObject);
|
62
65
|
rb_define_method(image_class, "read_metadata", (Method)image_read_metadata, 0);
|
63
66
|
rb_define_method(image_class, "iptc_data", (Method)image_iptc_data, 0);
|
67
|
+
rb_define_method(image_class, "xmp_data", (Method)image_xmp_data, 0);
|
64
68
|
rb_define_method(image_class, "exif_data", (Method)image_exif_data, 0);
|
65
69
|
|
66
70
|
image_factory_class = rb_define_class_under(exiv2_module, "ImageFactory", rb_cObject);
|
@@ -73,6 +77,10 @@ extern "C" {
|
|
73
77
|
iptc_data_class = rb_define_class_under(exiv2_module, "IptcData", rb_cObject);
|
74
78
|
rb_include_module(iptc_data_class, enumerable_module);
|
75
79
|
rb_define_method(iptc_data_class, "each", (Method)iptc_data_each, 0);
|
80
|
+
|
81
|
+
xmp_data_class = rb_define_class_under(exiv2_module, "XmpData", rb_cObject);
|
82
|
+
rb_include_module(xmp_data_class, enumerable_module);
|
83
|
+
rb_define_method(xmp_data_class, "each", (Method)xmp_data_each, 0);
|
76
84
|
}
|
77
85
|
|
78
86
|
|
@@ -117,6 +125,15 @@ extern "C" {
|
|
117
125
|
}
|
118
126
|
|
119
127
|
|
128
|
+
static VALUE image_xmp_data(VALUE self) {
|
129
|
+
Exiv2::Image* image;
|
130
|
+
Data_Get_Struct(self, Exiv2::Image, image);
|
131
|
+
|
132
|
+
VALUE xmp_data = Data_Wrap_Struct(xmp_data_class, 0, 0, &image->xmpData());
|
133
|
+
rb_iv_set(xmp_data, "@image", self); // Make sure we don't GC the image until there are no references to the XMP data left.
|
134
|
+
|
135
|
+
return xmp_data;
|
136
|
+
}
|
120
137
|
// Exiv2::ImageFactory methods
|
121
138
|
|
122
139
|
static VALUE image_factory_open(VALUE klass, VALUE path) {
|
@@ -146,5 +163,10 @@ extern "C" {
|
|
146
163
|
static VALUE iptc_data_each(VALUE self) {
|
147
164
|
return metadata_each<Exiv2::IptcData>(self);
|
148
165
|
}
|
166
|
+
|
167
|
+
// Exiv2::XmpData methods
|
149
168
|
|
169
|
+
static VALUE xmp_data_each(VALUE self) {
|
170
|
+
return metadata_each<Exiv2::XmpData>(self);
|
171
|
+
}
|
150
172
|
}
|
data/lib/exiv2/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
class Exiv2::XmpData
|
2
|
+
def to_hash
|
3
|
+
result = {}
|
4
|
+
|
5
|
+
self.each do |key, value|
|
6
|
+
if result[key]
|
7
|
+
if result[key].is_a? Array
|
8
|
+
result[key] << value
|
9
|
+
else
|
10
|
+
result[key] = [result[key], value]
|
11
|
+
end
|
12
|
+
else
|
13
|
+
result[key] = value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
result
|
17
|
+
end
|
18
|
+
|
19
|
+
def inspect
|
20
|
+
"#<Exiv2::XmpData: #{self.to_hash.inspect}>"
|
21
|
+
end
|
22
|
+
end
|
data/lib/exiv2.rb
CHANGED
data/spec/exiv2_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'exiv2'
|
2
2
|
|
3
3
|
describe Exiv2 do
|
4
|
+
|
4
5
|
it "should read IPTC data" do
|
5
6
|
image = Exiv2::ImageFactory.open("spec/files/test.jpg")
|
6
7
|
image.read_metadata
|
@@ -36,4 +37,30 @@ describe Exiv2 do
|
|
36
37
|
Exiv2::ImageFactory.open("tmp/no-such-file.jpg")
|
37
38
|
}.should raise_error(Exiv2::BasicError)
|
38
39
|
end
|
40
|
+
|
41
|
+
it "should read XMP data" do
|
42
|
+
image = Exiv2::ImageFactory.open("spec/files/test.jpg")
|
43
|
+
image.read_metadata
|
44
|
+
xmp_data = image.xmp_data
|
45
|
+
xmp_data.should be_a(Exiv2::XmpData)
|
46
|
+
xmp_data.inspect.should == '#<Exiv2::XmpData: {"Xmp.dc.description"=>"lang=\"x-default\" This is a description", "Xmp.dc.title"=>"lang=\"x-default\" Pickled"}>'
|
47
|
+
xmp_data.to_a.should == [
|
48
|
+
["Xmp.dc.title", "lang=\"x-default\" Pickled"],
|
49
|
+
["Xmp.dc.description", "lang=\"x-default\" This is a description"]
|
50
|
+
]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should convert xmp data into a hash" do
|
54
|
+
image = Exiv2::ImageFactory.open("spec/files/test.jpg")
|
55
|
+
image.read_metadata
|
56
|
+
iptc_hash = image.xmp_data.to_hash
|
57
|
+
iptc_hash.should be_a(Hash)
|
58
|
+
iptc_hash.should == {
|
59
|
+
"Xmp.dc.title" => "lang=\"x-default\" Pickled",
|
60
|
+
"Xmp.dc.description" => "lang=\"x-default\" This is a description"
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
|
39
66
|
end
|
data/spec/files/test.jpg
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exiv2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pete Yandell
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-17 00:00:00 +10:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- lib/exiv2.rb
|
69
69
|
- lib/exiv2/iptc_data.rb
|
70
70
|
- lib/exiv2/version.rb
|
71
|
+
- lib/exiv2/xmp_data.rb
|
71
72
|
- spec/exiv2_spec.rb
|
72
73
|
- spec/files/test.jpg
|
73
74
|
has_rdoc: true
|
@@ -101,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
102
|
requirements: []
|
102
103
|
|
103
104
|
rubyforge_project: exiv2
|
104
|
-
rubygems_version: 1.
|
105
|
+
rubygems_version: 1.6.2
|
105
106
|
signing_key:
|
106
107
|
specification_version: 3
|
107
108
|
summary: A simple wrapper around Exiv2
|