hydra-derivatives 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e62821ad5807bc96b9df2c9e2fda733081bb06a
4
- data.tar.gz: c3d04f3be7dbb1241f6c51043fbca299370a255b
3
+ metadata.gz: 168e645949c93b6ed1981c164f86969d71024cea
4
+ data.tar.gz: cecd38bd8f89d9de5d6e709cd3a409ee1792f4c7
5
5
  SHA512:
6
- metadata.gz: 01e2f3cfdc4a190d122219cbf16f455f50a98fa1b7eab0598350aecdd58ac3bcaa53e07d5d7b0af0845788aabd91d9025e34aa9c35c17020165f0f69c6dc6adc
7
- data.tar.gz: 7004d501623dc2667189951292421b436d8c441b5e8373f7d393a951a793ae226a1f0f721ec8b234373044c4d8900724f1bc3012924ac14d894e14d8c0abf5af
6
+ metadata.gz: 5ccf06b680a87e68f1375d662439edaa451560bd3895c0262032fd8357b7d4f235b2ebf142ac5d2eb78d2aeeac3da2f337cf04473b329ce0e3063a329c4f46fd
7
+ data.tar.gz: dc693c6c09dde061948bccae85c67576cea915e668d5b7d7bb5e9ca9544950ba9678e087df0b68360e4be5d90e1b9ed60c96c1c7276df37e73dd80c70ea9900a
data/History.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.0.5 (2013-07-25)
2
+ - Allow images to change format without being resize [Justin Coyne]
3
+
1
4
  ## 0.0.4 (2013-07-25)
2
5
  - Handle invalid mime-type on the datastream [Justin Coyne]
3
6
 
data/README.md CHANGED
@@ -67,7 +67,15 @@ Then when you call `obj.create_derivatives` a new datastream, called 'thumbnail'
67
67
 
68
68
  We recommend you run `obj.create_derivatives` in a background worker, because some derivative creation (especially videos) can take a long time.
69
69
 
70
- You may want to adjust your path to add LibreOffice and Fits.sh support:
70
+ # Installation
71
+
72
+ ## Dependencies
73
+
74
+ * [Fits](https://code.google.com/p/fits/)
75
+ * [LibreOffice](https://www.libreoffice.org/)
76
+
77
+ To enable LibreOffice and Fits.sh support, you must make sure they are on your path. Most people will put that in their .bash_profile or somewhere similar. For example:
78
+
71
79
  ```bash
72
80
  # in .bash_profile
73
81
  export PATH=${PATH}:/Users/justin/workspace/fits-0.6.2:/Applications/LibreOffice.app/Contents/MacOS
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -3,42 +3,38 @@ module Hydra
3
3
  class Image < Processor
4
4
  def process
5
5
  directives.each do |name, args|
6
- size = args
7
- output_datastream_name = output_datastream_id(name)
8
- if args.kind_of? Hash
9
- size = args[:size]
10
- output_datastream_name = args[:datastream] if args[:datastream]
11
- end
12
- create_resized_image(output_datastream_name, size, new_mime_type)
6
+ opts = args.kind_of?(Hash) ? args : {size: args}
7
+ format = opts.fetch(:format, 'png')
8
+ output_datastream_name = opts.fetch(:datastream, output_datastream_id(name))
9
+ create_resized_image(output_datastream(output_datastream_name), opts[:size], format)
13
10
  end
14
11
  end
15
12
 
16
-
17
13
  protected
18
14
 
19
- def new_mime_type
20
- 'image/png'
15
+ def new_mime_type(format)
16
+ MIME::Types.type_for(format).first.to_s
21
17
  end
22
18
 
23
-
24
- def create_resized_image(output_dsid, size, mime_type, quality=nil)
25
- create_image(output_dsid, mime_type, quality) do |xfrm|
26
- xfrm.change_geometry!(size) do |cols, rows, img|
27
- img.resize!(cols, rows)
19
+ def create_resized_image(output_ds, size, format, quality=nil)
20
+ create_image(output_ds, format, quality) do |xfrm|
21
+ if size
22
+ xfrm.change_geometry!(size) do |cols, rows, img|
23
+ img.resize!(cols, rows)
24
+ end
28
25
  end
29
26
  end
27
+ output_ds.mimeType = new_mime_type(format)
30
28
  end
31
29
 
32
- def create_image(dsid, mime_type, quality=nil)
30
+ def create_image(output_datastream, format, quality=nil)
33
31
  xfrm = load_image_transformer
34
32
  yield(xfrm) if block_given?
35
- #out = output_datastream
36
- output_datastream(dsid).content = if quality
37
- xfrm.to_blob { self.quality = quality }
33
+ output_datastream.content = if quality
34
+ xfrm.to_blob { self.quality = quality; self.format = format.upcase }
38
35
  else
39
- xfrm.to_blob
36
+ xfrm.to_blob { self.format = format.upcase }
40
37
  end
41
- output_datastream(dsid).mimeType = mime_type
42
38
  end
43
39
 
44
40
  # Override this method if you want a different transformer, or need to load the
@@ -1,20 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Hydra::Derivatives::Image do
4
+ let(:object) { ActiveFedora::Base.new }
4
5
  describe "when arguments are passed as a string" do
5
6
  let(:directives) {{ :thumb => "100x100>" } }
6
- subject { Hydra::Derivatives::Image.new(double(:obj), 'content', directives)}
7
+ subject { Hydra::Derivatives::Image.new(object, 'content', directives)}
7
8
 
8
9
  it "should use the string as the size and the name is autogenerated" do
9
- subject.should_receive(:create_resized_image).with("content_thumb", "100x100>", 'image/png')
10
+ subject.should_receive(:create_resized_image).with(an_instance_of(ActiveFedora::Datastream), "100x100>", 'png') do |ds|
11
+ ds.dsid.should == 'content_thumb'
12
+ end
10
13
  subject.process
11
14
  end
12
15
  end
13
16
  describe "when arguments are passed as a hash" do
14
17
  let(:directives) {{ :thumb => {size: "200x300>", datastream: 'thumbnail'} }}
15
- subject { Hydra::Derivatives::Image.new(double(:obj), 'content', directives)}
18
+ subject { Hydra::Derivatives::Image.new(object, 'content', directives)}
16
19
  it "should use the specified size and name" do
17
- subject.should_receive(:create_resized_image).with("thumbnail", "200x300>", 'image/png')
20
+ subject.should_receive(:create_resized_image).with(an_instance_of(ActiveFedora::Datastream), "200x300>", 'png') do |ds|
21
+ ds.dsid.should == 'thumbnail'
22
+ end
18
23
  subject.process
19
24
 
20
25
  end
@@ -23,7 +23,7 @@ describe "Transcoder" do
23
23
  when 'video/avi'
24
24
  obj.transform_datastream :content, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video
25
25
  when 'image/png', 'image/jpg'
26
- obj.transform_datastream :content, { :medium => "300x300>", :thumb => "100x100>" }
26
+ obj.transform_datastream :content, { :medium => "300x300>", :thumb => "100x100>", :access => {format: 'jpg', datastream: 'access'} }
27
27
  when 'application/vnd.ms-powerpoint'
28
28
  obj.transform_datastream :content, { :access => { :format=>'pdf' } }, processor: 'document'
29
29
  when 'text/rtf'
@@ -53,6 +53,8 @@ describe "Transcoder" do
53
53
  file.datastreams['content_medium'].mimeType.should == 'image/png'
54
54
  file.datastreams['content_thumb'].should have_content
55
55
  file.datastreams['content_thumb'].mimeType.should == 'image/png'
56
+ file.datastreams['access'].should have_content
57
+ file.datastreams['access'].mimeType.should == 'image/jpeg'
56
58
  file.datastreams.key?('content_text').should be_false
57
59
  end
58
60
  end
@@ -82,12 +84,12 @@ describe "Transcoder" do
82
84
  end
83
85
  end
84
86
 
85
- describe "when the source datastrem has an unknown mime_type" do
87
+ describe "when the source datastrem has an unknown mime_type", unless: ENV['TRAVIS'] == 'true' do
86
88
  let(:attachment) { File.open(File.expand_path('../../fixtures/piano_note.wav', __FILE__))}
87
89
  let(:file) { GenericFile.new(mime_type: 'audio/wav').tap { |t| t.content.content = attachment; t.content.mimeType = 'audio/vnd.wav'; t.save } }
88
90
 
89
91
  it "should transcode" do
90
- expect(logger).to receive(:warn).with("Unable to find a registered mime type for \"audio/vnd.wav\" on #{file.pid}").twice
92
+ expect(logger).to receive(:warn).with("Unable to find a registered mime type for \"audio/vnd.wav\" on #{file.pid}").at_least(1).times
91
93
  file.create_derivatives
92
94
  file.datastreams['content_mp3'].should have_content
93
95
  file.datastreams['content_mp3'].mimeType.should == 'audio/mpeg'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-derivatives
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne