This repository has been archived by the owner on May 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracting PNG splitter strategy from IIIF Print
Related to: - scientist-softserv/iiif_print#194 - samvera/bulkrax#760 - scientist-softserv/utk-hyku#343 - https://github.com/scientist-softserv/adventist-dl/issues/330
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module SpaceStone | ||
module PdfSplitter | ||
module Strategies | ||
# The purpose of this class is to split the PDF into constituent png files. | ||
class Png < Strategies::Base | ||
self.image_extension = 'png' | ||
|
||
def gsdevice | ||
return @gsdevice if defined?(@gsdevice) | ||
|
||
color = pdf_pages_summary.color_description | ||
bits_per_channel = pdf_pages_summary.bits_per_channel | ||
if color == 'gray' | ||
# 1 Bit Grayscale, if applicable: | ||
return @gsdevice = 'pngmonod' if bits_per_channel == 1 | ||
return @gsdevice = 'pnggray' if bits_per_channel > 1 | ||
end | ||
|
||
@gsdevice = 'png16m' | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
require 'spec_helper' | ||
|
||
RSpec.describe SpaceStone::PdfSplitter::Strategies::Png do | ||
let(:path) { __FILE__ } | ||
let(:pdf_pages_summary) { double(SpaceStone::PdfSplitter::PdfPagesSummary) } | ||
|
||
let(:splitter) { described_class.new(path, pdf_pages_summary: pdf_pages_summary) } | ||
|
||
describe '.compression' do | ||
subject { described_class.compression } | ||
it { is_expected.to be_nil } | ||
end | ||
|
||
describe '.compression?' do | ||
subject { described_class.compression? } | ||
it { is_expected.to be_falsey } | ||
end | ||
|
||
describe '.image_extension' do | ||
subject { described_class.image_extension } | ||
it { is_expected.to eq('png') } | ||
end | ||
|
||
describe '#gsdevice' do | ||
DEFAULT_SUMMARY_ATTRIBUTES = { | ||
color_description: 'rgb', | ||
bits_per_channel: 0 | ||
}.freeze | ||
|
||
[ | ||
[{ color_description: 'gray', bits_per_channel: 2 }, 'pnggray'], | ||
[{ color_description: 'gray', bits_per_channel: 1 }, 'pngmonod'], | ||
[{ color_description: 'rgb', bits_per_channel: 1 }, 'png16m'] | ||
].each do |attributes, expected_value| | ||
context 'with #{attributes.inspect}' do | ||
it "is expected to be #{expected_value.inspect}" do | ||
summary = SpaceStone::PdfSplitter::PdfPagesSummary.new(**DEFAULT_SUMMARY_ATTRIBUTES.merge(attributes)) | ||
expect(described_class.new(__FILE__, pdf_pages_summary: summary).gsdevice).to eq(expected_value) | ||
end | ||
end | ||
end | ||
end | ||
end |