Module: Cul::Hydra::Models::ImageResource
- Included in:
- GenericResource, Resource
- Defined in:
- app/models/concerns/cul/hydra/models/image_resource.rb
Constant Summary collapse
- IMAGE_EXT =
{"image/bmp" => 'bmp', "image/gif" => 'gif', "image/jpeg" => 'jpg', "image/png" => 'png', "image/tiff" => 'tif', "image/x-windows-bmp" => 'bmp', 'image/jp2' => 'jp2'}
- WIDTH =
RDF::URI(ActiveFedora::Predicates.find_graph_predicate(:image_width))
- LENGTH =
RDF::URI(ActiveFedora::Predicates.find_graph_predicate(:image_length))
- WIDTH_PREDICATE =
ActiveFedora::Predicates.short_predicate("http://www.w3.org/2003/12/exif/ns#imageWidth").to_s
- LENGTH_PREDICATE =
ActiveFedora::Predicates.short_predicate("http://www.w3.org/2003/12/exif/ns#imageLength").to_s
- EXTENT_PREDICATE =
ActiveFedora::Predicates.short_predicate("http://purl.org/dc/terms/extent").to_s
- FORMAT_OF_PREDICATE =
ActiveFedora::Predicates.short_predicate("http://purl.org/dc/terms/isFormatOf").to_s
- FORMAT_URI =
RDF::URI("http://purl.org/dc/terms/format")
- DJATOKA_THUMBNAIL_PARMS =
{ "url_ver" => "Z39.88-2004", "svc_id" => "info:lanl-repo/svc/getRegion", "svc_val_fmt" => "info:ofi/fmt:kev:mtx:jpeg2000", "svc.format" => "image/jpeg", "svc.level" => "", "svc.rotate" => "0", "svc.scale" => "200", "svc.clayers" => "" }
- DJATOKA_BASE_URL =
"http://iris.cul.columbia.edu:8888/resolve"
- EXIF_ORIENTATION_TO_DEGREES =
{ 'top-left' => 0, 'left-bottom' => 90, 'bottom-right' => 180, 'right-top' => 270 }
- DEGREES_TO_EXIF_ORIENTATIONS =
EXIF_ORIENTATION_TO_DEGREES.invert
Instance Method Summary collapse
- #length ⇒ Object
- #long ⇒ Object
- #orientation ⇒ Object
-
#orientation=(degrees) ⇒ Object
Allowed degrees arg values: 0, 90, 180, 270.
-
#required_rotation_for_upright_display ⇒ Object
The number of rotational degrees required to display this image as upright.
- #thumbnail_info ⇒ Object
- #width ⇒ Object
- #zooming? ⇒ Boolean
Instance Method Details
#length ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/concerns/cul/hydra/models/image_resource.rb', line 48 def length @length ||= begin ds = datastreams["content"] length = 0 unless ds.nil? or rels_int.relationships(ds,:exif_image_length).blank? length = rels_int.relationships(ds,:exif_image_length).first.object.to_s.to_i end length = relationships(:image_length).first.to_s.to_i if length == 0 length end end |
#long ⇒ Object
32 33 34 |
# File 'app/models/concerns/cul/hydra/models/image_resource.rb', line 32 def long @long_side ||= max(width(), length()) end |
#orientation ⇒ Object
102 103 104 |
# File 'app/models/concerns/cul/hydra/models/image_resource.rb', line 102 def orientation self.relationships(:orientation).present? ? EXIF_ORIENTATION_TO_DEGREES[self.relationships(:orientation).first.to_s] : 0 end |
#orientation=(degrees) ⇒ Object
Allowed degrees arg values: 0, 90, 180, 270
94 95 96 97 98 99 100 |
# File 'app/models/concerns/cul/hydra/models/image_resource.rb', line 94 def orientation=(degrees) degrees = degrees % 360 raise "Invalid value for degrees. Must be a right angle (0, 90, 180, etc.)" unless (degrees % 90 == 0) self.clear_relationship(:orientation) self.add_relationship(:orientation, DEGREES_TO_EXIF_ORIENTATIONS[degrees], true) return degrees # Hide RDF backing structure and make this look like a simple setter method end |
#required_rotation_for_upright_display ⇒ Object
The number of rotational degrees required to display this image as upright
88 89 90 91 |
# File 'app/models/concerns/cul/hydra/models/image_resource.rb', line 88 def required_rotation_for_upright_display required_rotation_orientation_in_degrees = (360 - self.orientation) % 360 return required_rotation_orientation_in_degrees end |
#thumbnail_info ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/models/concerns/cul/hydra/models/image_resource.rb', line 71 def thumbnail_info thumb = rels_int.relationships(datastreams['content'],:foaf_thumbnail).first if thumb t_dsid = thumb.object.to_s.split('/')[-1] t_url = "#{ActiveFedora.fedora_config.credentials[:url]}/objects/#{pid}/datastreams/#{t_dsid}/content" return {:url=>t_url,:mime=>datastreams[t_dsid].mimeType} elsif (zoom = self.zooming?) t_dsid = zoom.split('/')[-1] t_parms = DJATOKA_THUMBNAIL_PARMS.merge({"rft_id" => datastreams[t_dsid].dsLocation}) url = "#{DJATOKA_BASE_URL}?#{.map { |key, value| "#{CGI::escape(key.to_s)}=#{CGI::escape(value.to_s)}"}.join("&") }" {:url => url, :mime => t_parms["svc.format"]} else return {:asset=>"cul_scv_hydra/crystal/file.png",:mime=>'image/png'} end end |
#width ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/concerns/cul/hydra/models/image_resource.rb', line 36 def width @width ||= begin ds = datastreams["content"] width = 0 unless ds.nil? or rels_int.relationships(ds,:exif_image_width).blank? width = rels_int.relationships(ds,:exif_image_width).first.object.to_s.to_i end width = relationships(:image_width).first.to_s.to_i if width == 0 width end end |
#zooming? ⇒ Boolean
60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/concerns/cul/hydra/models/image_resource.rb', line 60 def zooming? zoom = rels_int.relationships(datastreams['content'],:foaf_zooming).first return zoom.object.to_s if zoom datastreams.each do |k,v| if v.mimeType =~ /image\/jp2$/i zoom = "info:fedora/#{k.dsid}" end end return zoom end |