ruby-exiv2 1.2 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -10,7 +10,12 @@ Basic usage:
10
10
  puts @img["Exif.Photo.PixelXDimension"]
11
11
  @img["Exif.Photo.PixelXDimension"] = 2048
12
12
  @img.save
13
-
14
-
15
13
 
14
+ Version 1.3 introduces dynamic accessors:
16
15
 
16
+ require 'exiv2'
17
+ @img = Exiv2::Image.new("a.jpg")
18
+ puts @img.Exif.Photo.PixelXDimension
19
+ @img.Exif.Photo.PixelXDimension = 2048
20
+ @img.save
21
+
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'rake/packagetask'
6
6
  require 'rake/contrib/rubyforgepublisher'
7
7
 
8
8
  PKG_NAME = "ruby-exiv2"
9
- PKG_VERSION = "1.2"
9
+ PKG_VERSION = "1.3"
10
10
  PKG_AUTHOR = "Max Lapshin"
11
11
  PKG_EMAIL = "max@maxidoors.ru"
12
12
  PKG_HOMEPAGE = "http://maxidoors.ru/"
@@ -217,6 +217,7 @@ void Init_image() {
217
217
  rb_define_singleton_method(cImage, "load_string", VALUEFUNC(exiv2_image_load_string), 1);
218
218
 
219
219
  rb_define_method(cImage, "exif", VALUEFUNC(exiv2_image_exif), 0);
220
+ rb_define_method(cImage, "Exif", VALUEFUNC(exiv2_image_exif), 0);
220
221
  rb_define_method(cImage, "iptc", VALUEFUNC(exiv2_image_iptc), 0);
221
222
 
222
223
  rb_define_method(cImage, "thumbnail", VALUEFUNC(exiv2_image_thumbnail), 1);
@@ -102,7 +102,7 @@ VALUE unmarshall_value(const Exiv2::Value& value) {
102
102
  Exiv2::TimeValue *time_value = dynamic_cast<Exiv2::TimeValue *>(const_cast<Exiv2::Value *>(&value));
103
103
  if(!time_value) return Qnil;
104
104
  Exiv2::TimeValue::Time time = time_value->getTime();
105
- return rb_funcall(rb_cTime, rb_intern("utc"), 6, INT2FIX(1970), INT2FIX(1), INT2FIX(1), INT2FIX(time.hour), INT2FIX(time.minute), INT2FIX(time.second));
105
+ return rb_funcall(rb_cTime, rb_intern("utc"), 6, INT2FIX(1970), INT2FIX(1), INT2FIX(1), INT2FIX(time.hour+time.tzHour), INT2FIX(time.minute+time.tzMinute), INT2FIX(time.second));
106
106
  }
107
107
 
108
108
  case Exiv2::invalid6:
@@ -3,6 +3,9 @@ begin
3
3
  rescue LoadError
4
4
  require File.dirname(__FILE__)+'/../ext/exiv2_bin'
5
5
  end
6
+ require 'enumerator'
7
+ require 'rubygems'
8
+ require 'active_support'
6
9
 
7
10
  module Exiv2
8
11
  #
@@ -29,4 +32,47 @@ module Exiv2
29
32
  Time.utc(date.year, date.month, date.day, time.hour, time.min, time.sec)
30
33
  end
31
34
  end
35
+
36
+ class SubTagAccess
37
+ def initialize(class_name, sub_tag, parent)
38
+ @class_name = class_name.split("::").last
39
+ @sub_tag = sub_tag
40
+ @parent = parent
41
+ end
42
+
43
+ def methods
44
+ @parent.select {|tag| tag.first.starts_with?("#{@class_name}.#{@sub_tag}")}.map {|tag| tag.first.gsub(/^(\w+)\.(\w+)\.(\w+)$/,'\3')}
45
+ end
46
+
47
+ def method_missing(name, *args)
48
+ method_name = name.to_s
49
+ method_name = method_name[0..-2] if method_name.ends_with?("=")
50
+ return super(name, *args) unless methods.include?(method_name)
51
+ if name.to_s.ends_with?("=")
52
+ @parent.send :[]=, "#{@class_name}.#{@sub_tag}.#{method_name}", *args
53
+ else
54
+ @parent.send :[], "#{@class_name}.#{@sub_tag}.#{method_name}", *args
55
+ end
56
+ end
57
+ end
58
+
59
+ module ExifAccess
60
+ include Enumerable
61
+ def methods
62
+ virtual_methods + real_methods
63
+ end
64
+ def method_missing(name, *args)
65
+ super(name, *args) unless virtual_methods.include?(name.to_s)
66
+ SubTagAccess.new(self.class.to_s, name, self)
67
+ end
68
+ private
69
+ def virtual_methods
70
+ self.map {|tag| tag.first.gsub(/^(\w+)\.(\w+)\.(\w+)$/,'\2')}.uniq
71
+ end
72
+ end
73
+
74
+ class Exif
75
+ alias :real_methods :methods
76
+ include ExifAccess
77
+ end
32
78
  end
Binary file
@@ -214,4 +214,22 @@ class ImageTest < Test::Unit::TestCase
214
214
  assert_equal Time.utc(2006, 3, 5, 15, 43, 23), @img.created_at
215
215
  end
216
216
  end
217
+
218
+ def test_time_marshall
219
+ open_test_file "RIA3001.jpg" do |filename|
220
+ assert @img = Exiv2::Image.new(filename)
221
+ assert_equal Time.utc(1970, 1, 1, 12, 10, 00), @img["Iptc.Application2.TimeCreated"]
222
+ end
223
+ end
224
+
225
+ def test_dynamic_accessors
226
+ open_test_file "smiley1.jpg" do |filename|
227
+ assert @img = Exiv2::Image.new(filename)
228
+ assert @img.Exif
229
+ assert_equal ["Flash", "PixelXDimension", "PixelYDimension"], @img.Exif.Photo.methods
230
+ assert_equal 140, @img.Exif.Photo.PixelYDimension
231
+ assert @img.Exif.Photo.PixelXDimension = 160
232
+ assert_equal 160, @img.Exif.Photo.PixelXDimension
233
+ end
234
+ end
217
235
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: ruby-exiv2
5
5
  version: !ruby/object:Gem::Version
6
- version: "1.2"
7
- date: 2007-04-12 00:00:00 +04:00
6
+ version: "1.3"
7
+ date: 2007-04-24 00:00:00 +04:00
8
8
  summary: Exiv2 (exif image tags handling) library driver
9
9
  require_paths:
10
10
  - lib
@@ -37,6 +37,7 @@ files:
37
37
  - test/image.rb
38
38
  - test/data/exiv2-fujifilm-finepix-s2pro.jpg
39
39
  - test/data/gps-test.jpg
40
+ - test/data/RIA3001.jpg
40
41
  - test/data/smiley1.jpg
41
42
  - ext/exif.cpp
42
43
  - ext/exiv2.cpp