Class: Hydra::Image
- Inherits:
-
ActiveFedora::Base
- Object
- ActiveFedora::Base
- Hydra::Image
- Includes:
- HTTParty, ModelMethods
- Defined in:
- vendor/plugins/hydra_repository/lib/hydra/image.rb
Defined Under Namespace
Classes: NoFileError, UnknownImageType
Constant Summary
- DEFAULT_IMAGE_DATASTREAMS =
["MASTER","MAX","THUMBNAIL","SCREEN"]
- DS_DEFAULTS =
{ :max => {:op => "convert", :convertTo => "jpg"}, :thumbnail => {:op => "resize",:newWidth=> 100}, :screen => {:op => "resize", :newWidth => 960} }
Instance Attribute Summary (collapse)
-
- (Object) derivations
Returns the value of attribute derivations.
-
- (Object) generate_derived_images
Returns the value of attribute generate_derived_images.
Instance Method Summary (collapse)
- - (Object) derivative_datastream(ds_name)
- - (Object) ds_options
- - (Object) image=(image_data)
-
- (Image) initialize(attrs = {})
constructor
A new instance of Image.
Methods included from ModelMethods
#apply_depositor_metadata, #insert_contributor, #remove_contributor, #set_collection_type
Constructor Details
- (Image) initialize(attrs = {})
A new instance of Image
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'vendor/plugins/hydra_repository/lib/hydra/image.rb', line 47 def initialize( attrs={}) existing_image = true if attrs[:pid] @generate_derived_images = attrs[:derivatives] ? attrs[:derivatives] : false super unless existing_image if attrs.has_key?(:file) #&& attrs[:file].class == File self.image = attrs[:file] attrs.delete(:file) elsif attrs.has_key?(:stream) && attrs.has_key?(:image_type) data = attrs[:stream] attrs.delete(:stream) self.image = data, attrs[:image_type] else #raise Hydra::Image::NoFileError, "No file indicated." end end end |
Instance Attribute Details
- (Object) derivations
Returns the value of attribute derivations
45 46 47 |
# File 'vendor/plugins/hydra_repository/lib/hydra/image.rb', line 45 def derivations @derivations end |
- (Object) generate_derived_images
Returns the value of attribute generate_derived_images
45 46 47 |
# File 'vendor/plugins/hydra_repository/lib/hydra/image.rb', line 45 def generate_derived_images @generate_derived_images end |
Instance Method Details
- (Object) derivative_datastream(ds_name)
103 104 105 106 107 108 109 |
# File 'vendor/plugins/hydra_repository/lib/hydra/image.rb', line 103 def derivative_datastream ds_name opts = [ds_name] ds_location = derivation_url(ds_name, opts) ds = ActiveFedora::Datastream.new(:dsid => ds_name.to_s.upcase, :label => ds_name.to_s.upcase, :dsLocation => ds_location, :controlGroup => "M", :mimeType => "image/jpeg") add_datastream(ds) save end |
- (Object) ds_options
95 96 97 98 99 100 101 |
# File 'vendor/plugins/hydra_repository/lib/hydra/image.rb', line 95 def if @derivations return DS_DEFAULTS.merge( @derivations ) else return DS_DEFAULTS end end |
- (Object) image=(image_data)
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'vendor/plugins/hydra_repository/lib/hydra/image.rb', line 76 def image=(image_data) delete_file_datastreams case image_data when File master_from_file image_data when Array needs_cleanup = true image_file = string_to_file(image_data[0],"MASTER",image_data[1]) master_from_file image_file when String master_from_url image_data else raise Hydra::Image::UnknownImageType, "Specified image is neither a file nor an appropriate image blob: #{image_data.class.to_s}" end save File.delete(image_file.path) if needs_cleanup generate_derivatives if @generate_derived_images end |