cul_image_props 0.2.3 → 0.3.0

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.
@@ -16,17 +16,15 @@ class Namespace
16
16
  @prefix
17
17
  end
18
18
  end
19
-
20
- ASSESS = Namespace.new("http://purl.oclc.org/NET/CUL/RESOURCE/STILLIMAGE/ASSESSMENT/","si-assess")
21
- BASIC = Namespace.new("http://purl.oclc.org/NET/CUL/RESOURCE/STILLIMAGE/BASIC/","si-basic")
19
+ MIME = {:bmp => 'image/bmp', :gif=>'image/gif', :jpg=>'image/jpeg', :png=>'image/png', :tif => 'image/tiff'}
20
+ EXIF = Namespace.new("http://www.w3.org/2003/12/exif/ns#","exif")
22
21
  DCMI = Namespace.new("http://purl.org/dc/terms/","dcmi")
23
-
22
+ RESOLUTION_VALUES = [1,2,3] # 1 => Not absolute, 2=>inches,3=>centimeters
24
23
  class Base
25
24
  attr_accessor :nodeset
26
25
  BASE_XML = Nokogiri::XML.parse(<<-xml
27
26
  <rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
28
- xmlns:si-assess="http://purl.oclc.org/NET/CUL/RESOURCE/STILLIMAGE/ASSESSMENT/"
29
- xmlns:si-basic="http://purl.oclc.org/NET/CUL/RESOURCE/STILLIMAGE/BASIC/"
27
+ xmlns:exif="http://www.w3.org/2003/12/exif/ns#"
30
28
  xmlns:dcmi="http://purl.org/dc/terms/"></rdf:Description>
31
29
  xml
32
30
  )
@@ -68,33 +66,35 @@ xml
68
66
  @ng_xml.root.add_child( prop )
69
67
  end
70
68
 
71
- def sampling_unit=(name)
72
- prop = @ng_xml.create_element("samplingFrequencyUnit")
73
- @ng_xml.root.namespace_definitions.each { |ns| prop.namespace = ns if ns.prefix == "si-assess" }
74
- @ng_xml.root.add_child( prop )
75
- prop.set_attribute("rdf:resource", prop.namespace.href + name)
69
+ def sampling_unit=(value)
70
+ raise "resolutionUnit values must be in the set #{RESOLUTION_VALUES.inspect}" unless RESOLUTION_VALUES.include? value
71
+ add_dt_prop("exif", "resolutionUnit", value)
76
72
  end
77
73
 
78
74
  def x_sampling_freq=(value)
79
- add_dt_prop("si-assess", "xSamplingFrequency", value)
75
+ add_dt_prop("exif", "xResolution", value)
80
76
  end
81
77
 
82
78
  def y_sampling_freq=(value)
83
- add_dt_prop("si-assess", "ySamplingFrequency", value)
79
+ add_dt_prop("exif", "yResolution", value)
84
80
  end
85
81
 
86
82
  def width=(value)
87
- add_dt_prop("si-basic", "imageWidth", value)
83
+ add_dt_prop("exif", "imageWidth", value)
88
84
  end
89
85
 
90
86
  def length=(value)
91
- add_dt_prop("si-basic", "imageLength", value)
87
+ add_dt_prop("exif", "imageLength", value)
92
88
  end
93
89
 
94
90
  def extent=(value)
95
91
  add_dt_prop("dcmi", "extent", value)
96
92
  end
97
93
 
94
+ def format=(value)
95
+ add_dt_prop("dcmi", "format", value)
96
+ end
97
+
98
98
  def hex_inspect(str)
99
99
  result = []
100
100
  (0...str.length).each {|ix| result << str[ix].to_s(16)}
@@ -113,9 +113,10 @@ class Bmp < Base
113
113
  header_bytes = header_bytes + @src.read(size)
114
114
  dims = header_bytes[0x12...0x1a].unpack('VV')
115
115
  sampling = header_bytes[0x26...0x2e].unpack('VV')
116
- self.sampling_unit='CentimeterSampling'
116
+ self.sampling_unit=3
117
117
  self.width= dims[0]
118
118
  self.length= dims[1]
119
+ self.format= MIME[:bmp]
119
120
  self.extent= srcfile.stat.size unless srcfile.nil?
120
121
  self.x_sampling_freq= (sampling[0]) # / 100).ceil
121
122
  self.y_sampling_freq= (sampling[1]) # / 100).ceil
@@ -132,6 +133,7 @@ class Gif < Base
132
133
  self.width= header_bytes[6,2].unpack('v')[0]
133
134
  self.length= header_bytes[8,2].unpack('v')[0]
134
135
  self.extent= srcfile.stat.size unless srcfile.nil?
136
+ self.format= MIME[:gif]
135
137
  end
136
138
  end
137
139
 
@@ -177,14 +179,15 @@ class Jpeg < Base
177
179
  end
178
180
  if tags.include? 'Image ResolutionUnit'
179
181
  if (tags['Image ResolutionUnit'].values[0] == 3)
180
- self.sampling_unit='CentimeterSampling'
182
+ self.sampling_unit=3
181
183
  elsif (tags['Image ResolutionUnit'].values[0] == 2)
182
- self.sampling_unit='InchSampling'
184
+ self.sampling_unit=2
183
185
  else
184
- self.sampling_unit='NoAbsoluteSampling'
186
+ self.sampling_unit=1
185
187
  end
186
188
  end
187
189
  self.extent= srcfile.stat.size unless srcfile.nil?
190
+ self.format= MIME[:jpg]
188
191
  end
189
192
  end
190
193
 
@@ -212,6 +215,7 @@ class Png < Base
212
215
  end
213
216
  end
214
217
  self.extent= srcfile.stat.size unless srcfile.nil?
218
+ self.format=MIME[:png]
215
219
  end
216
220
  def pHYs(len)
217
221
  val = @src.read(9)
@@ -221,9 +225,9 @@ class Png < Base
221
225
  if unit == 1 # resolution unit is METER
222
226
  xres = (xres / 100).ceil
223
227
  yres = (yres / 100).ceil
224
- self.sampling_unit='CentimeterSampling'
228
+ self.sampling_unit=3
225
229
  else
226
- self.sampling_unit='NoAbsoluteSampling'
230
+ self.sampling_unit=1
227
231
  end
228
232
  self.x_sampling_freq= xres
229
233
  self.y_sampling_freq= yres
@@ -325,15 +329,16 @@ class Tiff < Base
325
329
  end
326
330
  if tags.include? 'Image ResolutionUnit'
327
331
  if (tags['Image ResolutionUnit'].values[0] == 3)
328
- self.sampling_unit='CentimeterSampling'
332
+ self.sampling_unit=3
329
333
  elsif (tags['Image ResolutionUnit'].values[0] == 2)
330
- self.sampling_unit='InchSampling'
334
+ self.sampling_unit=2
331
335
  else
332
- self.sampling_unit='NoAbsoluteSampling'
336
+ self.sampling_unit=1
333
337
  end
334
338
  end
335
339
  # do stuff with tags
336
340
  self.extent= srcfile.stat.size unless srcfile.nil?
341
+ self.format=MIME[:tif]
337
342
  end
338
343
  end
339
344
 
@@ -1,7 +1,7 @@
1
1
  module Cul
2
2
  module Image
3
3
  module Properties
4
- VERSION = "0.2.3"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cul_image_props
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-21 00:00:00.000000000 Z
12
+ date: 2012-08-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri