sufia 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile +1 -1
- data/History.md +77 -0
- data/README.md +26 -11
- data/SUFIA_VERSION +1 -1
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +4 -3
- data/app/helpers/sufia_helper.rb +7 -5
- data/app/jobs/ingest_local_file_job.rb +34 -0
- data/app/views/catalog/_facet_selected.html.erb +1 -1
- data/app/views/generic_files/_local_file_import.html.erb +3 -0
- data/app/views/generic_files/new.html.erb +10 -0
- data/app/views/generic_files/upload/_alerts.html.erb +2 -2
- data/app/views/generic_files/upload/_local_file_import_chooser.html.erb +27 -0
- data/app/views/generic_files/upload/_script_templates.html.erb +1 -1
- data/lib/generators/sufia/sufia_generator.rb +1 -0
- data/lib/generators/sufia/templates/config/resque_config.rb +3 -20
- data/lib/sufia/files_controller/local_ingest_behavior.rb +54 -0
- data/lib/sufia/files_controller/upload_complete_behavior.rb +7 -0
- data/lib/sufia/files_controller_behavior.rb +31 -11
- data/lib/sufia/version.rb +1 -1
- data/spec/active_fedora/unsaved_digital_object_spec.rb +1 -1
- data/spec/controllers/authorities_controller_spec.rb +1 -1
- data/spec/controllers/batch_controller_spec.rb +4 -4
- data/spec/controllers/batch_edits_controller_spec.rb +1 -1
- data/spec/controllers/catalog_controller_spec.rb +1 -1
- data/spec/controllers/dashboard_controller_spec.rb +2 -2
- data/spec/controllers/downloads_controller_spec.rb +2 -3
- data/spec/controllers/generic_files_controller_spec.rb +113 -31
- data/spec/controllers/mailbox_controller_spec.rb +1 -1
- data/spec/controllers/single_use_link_controller_spec.rb +4 -5
- data/spec/controllers/users_controller_spec.rb +3 -3
- data/spec/features/browse_dashboard_files.rb +1 -1
- data/spec/features/browse_files.rb +1 -1
- data/spec/features/contact_form.rb +1 -1
- data/spec/features/display_dashboard.rb +1 -1
- data/spec/features/ingest_upload_files.rb +1 -1
- data/spec/features/users_spec.rb +1 -1
- data/spec/helpers/generic_file_helper_spec.rb +1 -1
- data/spec/helpers/render_constraints_helper_behavior_spec.rb +42 -0
- data/spec/helpers/sufia_helper_spec.rb +40 -1
- data/spec/jobs/import_url_job_spec.rb +45 -0
- data/spec/jobs/ingest_local_file_job_spec.rb +35 -0
- data/spec/lib/sufia/id_service_spec.rb +1 -1
- data/spec/lib/sufia/upload_complete_behavior_spec.rb +26 -0
- data/spec/models/audit_job_spec.rb +2 -2
- data/spec/models/batch_spec.rb +1 -1
- data/spec/models/batch_update_job_spec.rb +2 -4
- data/spec/models/characterize_job_spec.rb +17 -14
- data/spec/models/checksum_audit_log_spec.rb +2 -2
- data/spec/models/event_jobs_spec.rb +2 -2
- data/spec/models/file_content_datastream_spec.rb +5 -5
- data/spec/models/fits_datastream_spec.rb +2 -2
- data/spec/models/generic_file/actions_spec.rb +25 -0
- data/spec/models/generic_file/web_form_spec.rb +1 -1
- data/spec/models/generic_file_spec.rb +16 -33
- data/spec/models/local_authority_spec.rb +1 -1
- data/spec/models/properties_datastream_spec.rb +1 -1
- data/spec/models/single_use_link_spec.rb +1 -1
- data/spec/models/solr_document_spec.rb +1 -1
- data/spec/models/transcode_audio_job_spec.rb +22 -18
- data/spec/models/transcode_video_job_spec.rb +4 -3
- data/spec/models/trophy_spec.rb +1 -1
- data/spec/models/unzip_job_spec.rb +2 -2
- data/spec/models/user_spec.rb +1 -1
- data/spec/rake/sufia_fixtures_spec.rb +1 -1
- data/spec/routing/route_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -2
- data/spec/views/batch_edits/check_all_spec.rb +1 -1
- data/sufia-models/app/models/datastreams/file_content_datastream.rb +1 -15
- data/sufia-models/app/models/geo_names_resource.rb +0 -2
- data/sufia-models/lib/sufia/models.rb +1 -1
- data/sufia-models/lib/sufia/models/engine.rb +12 -1
- data/sufia-models/lib/sufia/models/file_content.rb +0 -3
- data/sufia-models/lib/sufia/models/generic_file.rb +6 -10
- data/sufia-models/lib/sufia/models/generic_file/actions.rb +1 -1
- data/sufia-models/lib/sufia/models/generic_file/characterization.rb +1 -1
- data/sufia-models/lib/sufia/models/generic_file/derivatives.rb +31 -0
- data/sufia-models/lib/sufia/models/generic_file/mime_types.rb +27 -0
- data/sufia-models/lib/sufia/models/generic_file/thumbnail.rb +6 -60
- data/sufia-models/lib/sufia/models/jobs/active_fedora_pid_based_job.rb +19 -0
- data/sufia-models/lib/sufia/models/jobs/audit_job.rb +12 -8
- data/sufia-models/lib/sufia/models/jobs/characterize_job.rb +3 -10
- data/sufia-models/lib/sufia/models/jobs/import_url_job.rb +2 -9
- data/sufia-models/lib/sufia/models/jobs/resolrize_job.rb +8 -1
- data/sufia-models/lib/sufia/models/jobs/transcode_audio_job.rb +4 -28
- data/sufia-models/lib/sufia/models/jobs/transcode_video_job.rb +4 -28
- data/sufia-models/lib/sufia/models/jobs/unzip_job.rb +5 -19
- data/sufia-models/lib/sufia/models/model_methods.rb +2 -16
- data/sufia-models/lib/sufia/models/user_local_directory_behavior.rb +29 -0
- data/sufia-models/lib/sufia/models/version.rb +1 -1
- data/sufia-models/sufia-models.gemspec +1 -1
- data/sufia.gemspec +2 -1
- data/tasks/sufia-dev.rake +1 -1
- metadata +26 -10
- data/app/assets/stylesheets/jquery-ui-1.8.1.custom.css +0 -486
- data/app/assets/stylesheets/jquery-ui-1.8.23.custom.css +0 -340
- data/sufia-models/lib/sufia/models/file_content/extract_metadata.rb +0 -60
- data/sufia-models/lib/sufia/models/jobs/ffmpeg_transcode_job.rb +0 -61
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe TranscodeAudioJob, :if => Sufia.config.enable_ffmpeg do
|
4
4
|
before do
|
@@ -7,18 +7,18 @@ describe TranscodeAudioJob, :if => Sufia.config.enable_ffmpeg do
|
|
7
7
|
@generic_file.stub(:characterize_if_changed).and_yield
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
@generic_file.delete
|
12
|
-
end
|
13
|
-
|
14
|
-
subject { TranscodeAudioJob.new(@generic_file.id, 'content')}
|
10
|
+
subject { TranscodeAudioJob.new(@generic_file.id)}
|
15
11
|
|
16
12
|
|
17
13
|
describe "with a wav file" do
|
18
14
|
before do
|
19
|
-
@generic_file.
|
15
|
+
@generic_file.add_file(File.open(fixture_path + '/piano_note.wav'), 'content', 'piano_note.wav')
|
20
16
|
@generic_file.save!
|
21
17
|
end
|
18
|
+
after do
|
19
|
+
@generic_file.delete
|
20
|
+
end
|
21
|
+
|
22
22
|
|
23
23
|
it "should transcode to mp3 and ogg" do
|
24
24
|
subject.run
|
@@ -26,7 +26,7 @@ describe TranscodeAudioJob, :if => Sufia.config.enable_ffmpeg do
|
|
26
26
|
derivative = reloaded.datastreams['mp3']
|
27
27
|
derivative.should_not be_nil
|
28
28
|
derivative.content.should_not be_nil
|
29
|
-
derivative.mimeType.should == 'audio/
|
29
|
+
derivative.mimeType.should == 'audio/mpeg'
|
30
30
|
|
31
31
|
derivative2 = reloaded.datastreams['ogg']
|
32
32
|
derivative2.should_not be_nil
|
@@ -36,13 +36,15 @@ describe TranscodeAudioJob, :if => Sufia.config.enable_ffmpeg do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "with an mp3 file" do
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
# Uncomment when this is nolonger pending
|
40
|
+
# before do
|
41
|
+
# @generic_file.add_file(File.open(fixture_path + '/sufia/sufia_test5.mp3'), 'content', 'sufia_test5.mp3')
|
42
|
+
# @generic_file.characterize # so that the mime_type is set
|
43
|
+
# @generic_file.save!
|
44
|
+
# end
|
44
45
|
|
45
46
|
it "should copy the content to the mp3 datastream and transcode to ogg" do
|
47
|
+
pending "Need a way to do this in hydra-derivatives"
|
46
48
|
subject.run
|
47
49
|
reloaded = GenericFile.find(@generic_file.pid)
|
48
50
|
derivative = reloaded.datastreams['mp3']
|
@@ -57,13 +59,15 @@ describe TranscodeAudioJob, :if => Sufia.config.enable_ffmpeg do
|
|
57
59
|
end
|
58
60
|
end
|
59
61
|
describe "with an ogg file" do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
# Uncomment when this is nolonger pending
|
63
|
+
# before do
|
64
|
+
# @generic_file.add_file(File.open(fixture_path + '/Example.ogg'), 'content', 'Example.ogg')
|
65
|
+
# @generic_file.characterize # so that the mime_type is set
|
66
|
+
# @generic_file.save!
|
67
|
+
# end
|
65
68
|
|
66
69
|
it "should copy the content to the ogg datastream and transcode to mp3" do
|
70
|
+
pending "Need a way to do this in hydra-derivatives"
|
67
71
|
subject.run
|
68
72
|
reloaded = GenericFile.find(@generic_file.pid)
|
69
73
|
derivative = reloaded.datastreams['mp3']
|
@@ -1,11 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe TranscodeVideoJob, :if => Sufia.config.enable_ffmpeg do
|
4
4
|
before do
|
5
5
|
@generic_file = GenericFile.new
|
6
6
|
@generic_file.apply_depositor_metadata('jcoyne@example.com')
|
7
|
-
@generic_file.
|
7
|
+
@generic_file.add_file(File.open(fixture_path + '/countdown.avi'), 'content', 'countdown.avi')
|
8
8
|
@generic_file.stub(:characterize_if_changed).and_yield
|
9
|
+
@generic_file.mime_type = 'video/avi'
|
9
10
|
@generic_file.save!
|
10
11
|
end
|
11
12
|
|
@@ -13,7 +14,7 @@ describe TranscodeVideoJob, :if => Sufia.config.enable_ffmpeg do
|
|
13
14
|
@generic_file.delete
|
14
15
|
end
|
15
16
|
|
16
|
-
subject { TranscodeVideoJob.new(@generic_file.id
|
17
|
+
subject { TranscodeVideoJob.new(@generic_file.id)}
|
17
18
|
it "should put content in datastream_out" do
|
18
19
|
subject.run
|
19
20
|
reloaded = GenericFile.find(@generic_file.pid)
|
data/spec/models/trophy_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe UnzipJob do
|
4
4
|
before do
|
5
5
|
@batch = Batch.create
|
6
6
|
@generic_file = GenericFile.new(:batch=>@batch)
|
7
|
-
@generic_file.
|
7
|
+
@generic_file.add_file(File.open(fixture_path + '/icons.zip'), 'content', 'icons.zip')
|
8
8
|
@generic_file.apply_depositor_metadata('mjg36')
|
9
9
|
@generic_file.stub(:characterize_if_changed).and_yield #don't run characterization
|
10
10
|
@generic_file.save
|
data/spec/models/user_spec.rb
CHANGED
data/spec/routing/route_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -19,8 +19,8 @@ $in_travis = !ENV['TRAVIS'].nil? && ENV['TRAVIS'] == 'true'
|
|
19
19
|
|
20
20
|
if $in_travis
|
21
21
|
# Monkey-patches the FITS runner to return the PDF FITS fixture
|
22
|
-
module
|
23
|
-
module
|
22
|
+
module Hydra
|
23
|
+
module Derivatives
|
24
24
|
module ExtractMetadata
|
25
25
|
def run_fits!(path)
|
26
26
|
File.open(File.join(File.expand_path('../fixtures', __FILE__), 'pdf_fits.xml')).read
|
@@ -1,18 +1,4 @@
|
|
1
|
-
# Copyright © 2012 The Pennsylvania State University
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
1
|
class FileContentDatastream < ActiveFedora::Datastream
|
16
|
-
include
|
2
|
+
include Hydra::Derivatives::ExtractMetadata
|
17
3
|
include Sufia::FileContent::Versions
|
18
4
|
end
|
@@ -5,7 +5,7 @@ require 'nest'
|
|
5
5
|
require 'mailboxer'
|
6
6
|
require 'acts_as_follower'
|
7
7
|
require 'paperclip'
|
8
|
-
require
|
8
|
+
require "active_resource" # used by GenericFile to catch errors & by GeoNamesResource
|
9
9
|
begin
|
10
10
|
# activerecord-import 0.3.1 does not support rails 4, so we don't require it.
|
11
11
|
require 'activerecord-import'
|
@@ -22,6 +22,7 @@ module Sufia
|
|
22
22
|
config.fits_path = "fits.sh"
|
23
23
|
config.enable_contact_form_delivery = false
|
24
24
|
config.dropbox_api_key = nil
|
25
|
+
config.enable_local_ingest = nil
|
25
26
|
config.queue = Sufia::Resque::Queue
|
26
27
|
|
27
28
|
config.autoload_paths += %W(
|
@@ -40,22 +41,32 @@ module Sufia
|
|
40
41
|
end
|
41
42
|
|
42
43
|
initializer 'requires' do
|
44
|
+
require 'hydra/derivatives'
|
43
45
|
require 'sufia/models/model_methods'
|
44
46
|
require 'sufia/models/noid'
|
45
47
|
require 'sufia/models/file_content'
|
46
|
-
require 'sufia/models/file_content/extract_metadata'
|
47
48
|
require 'sufia/models/file_content/versions'
|
48
49
|
require 'sufia/models/generic_file/actions'
|
49
50
|
require 'sufia/models/generic_file/audit'
|
50
51
|
require 'sufia/models/generic_file/characterization'
|
52
|
+
require 'sufia/models/generic_file/derivatives'
|
51
53
|
require 'sufia/models/generic_file/export'
|
54
|
+
require 'sufia/models/generic_file/mime_types'
|
52
55
|
require 'sufia/models/generic_file/permissions'
|
53
56
|
require 'sufia/models/generic_file/thumbnail'
|
54
57
|
require 'sufia/models/generic_file'
|
55
58
|
require 'sufia/models/user'
|
59
|
+
require 'sufia/models/user_local_directory_behavior'
|
56
60
|
require 'sufia/models/id_service'
|
57
61
|
require 'sufia/models/solr_document_behavior'
|
58
62
|
end
|
63
|
+
|
64
|
+
initializer 'configure' do
|
65
|
+
Hydra::Derivatives.ffmpeg_path = Sufia.config.ffmpeg_path
|
66
|
+
Hydra::Derivatives.temp_file_base = Sufia.config.temp_file_base
|
67
|
+
Hydra::Derivatives.fits_path = Sufia.config.fits_path
|
68
|
+
Hydra::Derivatives.enable_ffmpeg = Sufia.config.enable_ffmpeg
|
69
|
+
end
|
59
70
|
end
|
60
71
|
end
|
61
72
|
end
|
@@ -2,22 +2,20 @@ module Sufia
|
|
2
2
|
module GenericFile
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
extend ActiveSupport::Autoload
|
5
|
-
autoload :Export
|
6
|
-
autoload :Thumbnail
|
7
|
-
autoload :Characterization
|
8
|
-
autoload :Audit
|
9
5
|
autoload :Actions
|
10
6
|
autoload :Permissions
|
11
7
|
autoload :WebForm, 'sufia/models/generic_file/web_form'
|
12
8
|
autoload :AccessibleAttributes, 'sufia/models/generic_file/accessible_attributes'
|
13
9
|
include Sufia::ModelMethods
|
14
10
|
include Sufia::Noid
|
11
|
+
include Sufia::GenericFile::MimeTypes
|
15
12
|
include Sufia::GenericFile::Thumbnail
|
16
13
|
include Sufia::GenericFile::Export
|
17
14
|
include Sufia::GenericFile::Characterization
|
18
15
|
include Sufia::GenericFile::Audit
|
19
16
|
include Sufia::GenericFile::Permissions
|
20
17
|
include Sufia::GenericFile::WebForm
|
18
|
+
include Sufia::GenericFile::Derivatives
|
21
19
|
|
22
20
|
included do
|
23
21
|
has_metadata :name => "descMetadata", :type => GenericFileRdfDatastream
|
@@ -52,21 +50,19 @@ module Sufia
|
|
52
50
|
end
|
53
51
|
|
54
52
|
def pdf?
|
55
|
-
|
53
|
+
self.class.pdf_mime_types.include? self.mime_type
|
56
54
|
end
|
57
55
|
|
58
56
|
def image?
|
59
|
-
|
57
|
+
self.class.image_mime_types.include? self.mime_type
|
60
58
|
end
|
61
59
|
|
62
60
|
def video?
|
63
|
-
|
61
|
+
self.class.video_mime_types.include? self.mime_type
|
64
62
|
end
|
65
63
|
|
66
64
|
def audio?
|
67
|
-
|
68
|
-
# audio/mpeg is the mime type that fits 0.6.0 returns for an mp3 file.
|
69
|
-
['audio/mp3', 'audio/mpeg', 'audio/x-wave', 'audio/x-wav', 'audio/ogg'].include? self.mime_type
|
65
|
+
self.class.audio_mime_types.include? self.mime_type
|
70
66
|
end
|
71
67
|
|
72
68
|
def persistent_url
|
@@ -3,7 +3,7 @@ module Sufia::GenericFile
|
|
3
3
|
module Actions
|
4
4
|
def self.create_metadata(generic_file, user, batch_id)
|
5
5
|
|
6
|
-
generic_file.apply_depositor_metadata(user
|
6
|
+
generic_file.apply_depositor_metadata(user)
|
7
7
|
generic_file.date_uploaded = Date.today
|
8
8
|
generic_file.date_modified = Date.today
|
9
9
|
generic_file.creator = user.name
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Sufia
|
2
|
+
module GenericFile
|
3
|
+
module Derivatives
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include Hydra::Derivatives
|
8
|
+
|
9
|
+
makes_derivatives do |obj|
|
10
|
+
case obj.mime_type
|
11
|
+
when *pdf_mime_types
|
12
|
+
obj.transform_datastream :content,
|
13
|
+
{ :thumbnail => {size: "338x493", datastream: 'thumbnail'} }
|
14
|
+
when *audio_mime_types
|
15
|
+
obj.transform_datastream :content,
|
16
|
+
{ :mp3 => {format: 'mp3', datastream: 'mp3'},
|
17
|
+
:ogg => {format: 'ogg', datastream: 'ogg'} }, processor: :audio
|
18
|
+
when *video_mime_types
|
19
|
+
obj.transform_datastream :content,
|
20
|
+
{ :webm => {format: "webm", datastream: 'webm'},
|
21
|
+
:mp4 => {format: "mp4", datastream: 'mp4'} }, processor: :video
|
22
|
+
when *image_mime_types
|
23
|
+
obj.transform_datastream :content, { :thumbnail => {size: "200x150>", datastream: 'thumbnail'} }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Sufia
|
2
|
+
module GenericFile
|
3
|
+
module MimeTypes
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def image_mime_types
|
8
|
+
['image/png','image/jpeg', 'image/jpg', 'image/jp2', 'image/bmp', 'image/gif']
|
9
|
+
end
|
10
|
+
|
11
|
+
def pdf_mime_types
|
12
|
+
['application/pdf']
|
13
|
+
end
|
14
|
+
|
15
|
+
def video_mime_types
|
16
|
+
['video/mpeg', 'video/mp4', 'video/webm', 'video/x-msvideo', 'video/avi', 'video/quicktime', 'application/mxf']
|
17
|
+
end
|
18
|
+
|
19
|
+
def audio_mime_types
|
20
|
+
# audio/x-wave is the mime type that fits 0.6.0 returns for a wav file.
|
21
|
+
# audio/mpeg is the mime type that fits 0.6.0 returns for an mp3 file.
|
22
|
+
['audio/mp3', 'audio/mpeg', 'audio/wav', 'audio/x-wave', 'audio/x-wav', 'audio/ogg']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,17 +1,18 @@
|
|
1
1
|
module Sufia
|
2
2
|
module GenericFile
|
3
3
|
module Thumbnail
|
4
|
+
extend ActiveSupport::Concern
|
4
5
|
# Create thumbnail requires that the characterization has already been run (so mime_type, width and height is available)
|
5
6
|
# and that the object is already has a pid set
|
6
7
|
def create_thumbnail
|
7
8
|
return unless self.content.has_content?
|
8
|
-
|
9
|
-
|
10
|
-
elsif image?
|
11
|
-
create_image_thumbnail
|
12
|
-
elsif video?
|
9
|
+
|
10
|
+
if video?
|
13
11
|
create_video_thumbnail
|
12
|
+
else
|
13
|
+
create_derivatives
|
14
14
|
end
|
15
|
+
self.save
|
15
16
|
end
|
16
17
|
|
17
18
|
protected
|
@@ -29,61 +30,6 @@ module Sufia
|
|
29
30
|
|
30
31
|
self.thumbnail.content = File.open(output_file, 'rb').read
|
31
32
|
self.thumbnail.mimeType = 'image/png'
|
32
|
-
self.save
|
33
|
-
end
|
34
|
-
|
35
|
-
def create_pdf_thumbnail
|
36
|
-
retryCnt = 0
|
37
|
-
stat = false;
|
38
|
-
for retryCnt in 1..3
|
39
|
-
begin
|
40
|
-
pdf = load_image_transformer
|
41
|
-
first = pdf.to_a[0]
|
42
|
-
first.format = "PNG"
|
43
|
-
thumb = first.scale(338, 493)
|
44
|
-
self.thumbnail.content = thumb.to_blob { self.format = "PNG" }
|
45
|
-
self.thumbnail.mimeType = 'image/png'
|
46
|
-
self.save
|
47
|
-
break
|
48
|
-
rescue => e
|
49
|
-
logger.warn "Rescued an error #{e.inspect} retry count = #{retryCnt}"
|
50
|
-
sleep 1
|
51
|
-
end
|
52
|
-
end
|
53
|
-
return stat
|
54
|
-
end
|
55
|
-
|
56
|
-
def create_image_thumbnail
|
57
|
-
self.thumbnail.content = scale_image.to_blob { self.format = "PNG" }
|
58
|
-
self.thumbnail.mimeType = 'image/png'
|
59
|
-
#logger.debug "Has the content before saving? #{self.content.changed?}"
|
60
|
-
self.save
|
61
|
-
end
|
62
|
-
|
63
|
-
def scale_image
|
64
|
-
img = load_image_transformer
|
65
|
-
height = Float(self.height.first.to_i)
|
66
|
-
width = Float(self.width.first.to_i)
|
67
|
-
if width > height && width > 150 && height > 105
|
68
|
-
# horizontal img
|
69
|
-
scale = 150 / width
|
70
|
-
img.scale(150, height * scale)
|
71
|
-
elsif height >= width && width > 150 && height > 200
|
72
|
-
# vertical or square
|
73
|
-
scale = 200 / height
|
74
|
-
img.scale(width*scale, 200)
|
75
|
-
else
|
76
|
-
# Too small to worry about resizing
|
77
|
-
img
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# Override this method if you want a different transformer, or need to load the
|
82
|
-
# raw image from a different source (e.g. external datastream)
|
83
|
-
def load_image_transformer
|
84
|
-
xformer = Magick::ImageList.new
|
85
|
-
xformer.from_blob(content.content)
|
86
|
-
xformer
|
87
33
|
end
|
88
34
|
|
89
35
|
end
|