iptc 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,4 +8,6 @@ Read IPTC::JPEG::Image for more information.
8
8
  The IPTC library parses the APP13 JPEG Tag and generates a hash of properties for a given file.
9
9
 
10
10
  Original code from http://raa.ruby-lang.org/project/jpeg-jfif-iptc/
11
- Gemified, reorganized and modified in 2010 by Jens Kraemer.
11
+ Gemified, reorganized and modified in 2010 by Jens Kraemer.
12
+
13
+ Ownership retaken from Github in 2011 by Pierre Baillet.
@@ -31,7 +31,7 @@ module IPTC
31
31
  def initialize data_name, content, quick=true
32
32
  @logger = Logger.new(STDOUT)
33
33
  @logger.datetime_format = "%H:%M:%S"
34
- @logger.level = Logger::DEBUG # $DEBUG?(Logger::DEBUG):(Logger::INFO)
34
+ @logger.level = $DEBUG?(Logger::DEBUG):(Logger::INFO)
35
35
 
36
36
  @data_name = data_name
37
37
  @content = content
@@ -12,9 +12,9 @@ module IPTC
12
12
 
13
13
  # The NewMarker constructor method.
14
14
  # Inspect the object space in order to find something usable later
15
- def Marker.NewMarker(type,data, logger)
15
+ def Marker.NewMarker(type, data, logger)
16
16
  marker_class = "#{type}Marker"
17
- if JPEG::Markers.constants.include?(marker_class.to_s)
17
+ if JPEG::Markers.constants.include?(marker_class.to_sym)
18
18
  return JPEG::Markers.const_get(marker_class).new(type, data)
19
19
  else
20
20
  if !@@missing.include?(type)
@@ -39,7 +39,7 @@ module IPTC
39
39
  end
40
40
  end
41
41
 
42
- def initialize(type,data)
42
+ def initialize(type, data)
43
43
  @logger = Logger.new(STDOUT)
44
44
  @logger.datetime_format = "%H:%M:%S"
45
45
  @logger.level = $DEBUG?(Logger::DEBUG):(Logger::INFO)
@@ -1,3 +1,5 @@
1
+ # -*- coding: binary -*-
2
+
1
3
  module IPTC
2
4
  module JPEG
3
5
  MARKERS = {
@@ -43,7 +43,7 @@ module IPTC
43
43
  # See also the IPTC::MarkerNomenclature.
44
44
  class APP13Marker < Marker
45
45
  def initialize(type, data)
46
- @header = "Photoshop 3.0\0008BIM"
46
+ @header = "Photoshop 3.0\000"
47
47
 
48
48
  super(type, data)
49
49
  @prefix = "iptc"
@@ -53,46 +53,85 @@ module IPTC
53
53
  return read(@header.length)==@header
54
54
  end
55
55
 
56
+ SHORT = 1
57
+ WORD = 2
58
+ LONG = 4
59
+
60
+ def word
61
+ read(WORD).unpack("n")[0]
62
+ end
63
+ def long
64
+ read(LONG).unpack("N")[0]
65
+ end
66
+
56
67
  def parse
57
68
  l "APP13 marker parsed"
58
- @markers = Array.new
69
+ @markers = Array.new
70
+
71
+ # http://www.fileformat.info/format/psd/egff.htm
72
+ # this one is much up to date.
59
73
 
74
+ while @content.pos < @content.length - 1
75
+ l @content.pos
76
+ l @content.length
60
77
 
61
- @bim_type = read(2)
62
- @bim_dummy = read(4)
63
- size = read(2)
78
+ eight_bim = read(LONG)
79
+ l eight_bim
80
+ raise "Not a 8BIM packet(#{eight_bim.inspect} #{read(10)}" if eight_bim != "8BIM"
81
+ @bim_type = word()
64
82
 
65
- content = StringIO.new(read(size.unpack('n')[0]))
83
+ # Read name length and normalize to even number of bytes
84
+ # Weird, always read 4 bytes
85
+ padding = read(4)
86
+ bim_size = word()
66
87
 
67
- while !content.eof?
88
+ # http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Photoshop.html
89
+ case @bim_type
68
90
 
69
- header = content.read(2)
91
+ when 0x0404 # IPTC
92
+ content = StringIO.new(read(bim_size))
70
93
 
71
- # http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html
72
- case header
73
- when "\x1c\x01"
74
- # skip the envelope
75
94
  while !content.eof?
76
- if content.read(1) == "\x1c"
77
- content.pos = content.pos - 1
78
- break
95
+
96
+ header = content.read(2).unpack("n")[0]
97
+
98
+ # http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html
99
+ case header
100
+ when 0x1C01
101
+ # skip the envelope
102
+ while !content.eof?
103
+ if content.read(1) == "\x1c"
104
+ content.pos = content.pos - 1
105
+ break
106
+ end
107
+ end
108
+ when 0x1C02
109
+
110
+ type = content.read(1).unpack('c')[0]
111
+ size = content.read(2)
112
+ value = content.read(size.unpack('n')[0])
113
+
114
+ l "Found marker #{type}"
115
+ marker = IPTC::Marker.new(type, value)
116
+ @values[@prefix+"/"+IPTC::MarkerNomenclature.markers(type.to_i).name] ||= []
117
+ @values[@prefix+"/"+IPTC::MarkerNomenclature.markers(type.to_i).name] << value
118
+ @markers << marker
119
+
120
+ else
121
+ # raise InvalidBlockException.new("Invalid BIM segment #{header.inspect} in marker\n#{@original_content.inspect}")
79
122
  end
80
123
  end
81
- when "\x1c\x02"
82
-
83
- type = content.read(1).unpack('c')[0]
84
- size = content.read(2)
85
- value = content.read(size.unpack('n')[0])
86
-
87
- l "Found marker #{type}"
88
- marker = IPTC::Marker.new(type, value)
89
- @values[@prefix+"/"+IPTC::MarkerNomenclature.markers(type.to_i).name] ||= []
90
- @values[@prefix+"/"+IPTC::MarkerNomenclature.markers(type.to_i).name] << value
91
- @markers << marker
92
-
124
+ when 0x03ED
125
+ hRes = long()
126
+ hResUnit = word()
127
+ widthUnit = word()
128
+ vRes = long()
129
+ vResUnit = word()
130
+ heightUnit = word()
93
131
  else
94
- # raise InvalidBlockException.new("Invalid BIM segment #{header.inspect} in marker\n#{@original_content.inspect}")
132
+ read(bim_size)
95
133
  end
134
+ read(1) if bim_size%2 == 1
96
135
  end
97
136
  return @values
98
137
  end
@@ -31,6 +31,9 @@ module IPTC
31
31
  end
32
32
  end
33
33
  end
34
+ def keys
35
+ return @internal.keys
36
+ end
34
37
  def each
35
38
  @internal.each do |key, values|
36
39
  values.each do |value|
@@ -1,3 +1,3 @@
1
1
  module IPTC
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,35 +1,26 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: iptc
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 5
10
- version: 0.0.5
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Pierre Baillet
14
9
  - Jens Kraemer
10
+ - Tristan Bartement
15
11
  autorequire:
16
12
  bindir: bin
17
13
  cert_chain: []
18
-
19
- date: 2012-01-09 00:00:00 +01:00
20
- default_executable:
14
+ date: 2013-02-27 00:00:00.000000000 Z
21
15
  dependencies: []
22
-
23
- description: Original code from http://raa.ruby-lang.org/project/jpeg-jfif-iptc/, gemified and updated by Jens Kraemer, Futher fixes by Pierre Baillet
24
- email:
16
+ description: Original code from http://raa.ruby-lang.org/project/jpeg-jfif-iptc/,
17
+ gemified and updated by Jens Kraemer, Futher fixes by Pierre Baillet
18
+ email:
25
19
  - pierre@baillet.name
26
20
  executables: []
27
-
28
21
  extensions: []
29
-
30
22
  extra_rdoc_files: []
31
-
32
- files:
23
+ files:
33
24
  - lib/iptc/jpeg/image.rb
34
25
  - lib/iptc/jpeg/marker.rb
35
26
  - lib/iptc/jpeg/marker_headers.rb
@@ -42,41 +33,28 @@ files:
42
33
  - lib/iptc.rb
43
34
  - LICENSE
44
35
  - README.md
45
- has_rdoc: true
46
36
  homepage: http://github.com/octplane/ruby-iptc
47
37
  licenses: []
48
-
49
38
  post_install_message:
50
39
  rdoc_options: []
51
-
52
- require_paths:
40
+ require_paths:
53
41
  - lib
54
- required_ruby_version: !ruby/object:Gem::Requirement
42
+ required_ruby_version: !ruby/object:Gem::Requirement
55
43
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
63
- required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
49
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- hash: 23
69
- segments:
70
- - 1
71
- - 3
72
- - 6
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
73
53
  version: 1.3.6
74
54
  requirements: []
75
-
76
55
  rubyforge_project: ruby-iptc
77
- rubygems_version: 1.6.2
56
+ rubygems_version: 1.8.23
78
57
  signing_key:
79
58
  specification_version: 3
80
59
  summary: Pure ruby IPTC metadata reader
81
60
  test_files: []
82
-