Skip to content

Commit

Permalink
Merge pull request #691 from xtreme-tanzeeb-khalili/master
Browse files Browse the repository at this point in the history
Add more sophisticated multi-page PDF support
  • Loading branch information
bensie committed Apr 10, 2012
2 parents c7826c5 + 3120a5d commit ed1b899
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
7 changes: 4 additions & 3 deletions lib/carrierwave/processing/rmagick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,14 @@ def manipulate!(options={})

frames = if image.size > 1
list = ::Magick::ImageList.new
image.each do |frame|
list << (block_given? ? yield( frame ) : frame)
image.each_with_index do |frame, index|
processed_frame = block_given? ? yield( frame, index ) : frame
list << processed_frame if processed_frame
end
block_given? ? list : list.append(true)
else
frame = image.first
frame = yield( frame ) if block_given?
frame = yield( frame, 0 ) if block_given?
frame
end

Expand Down
44 changes: 39 additions & 5 deletions spec/uploader/processing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,45 @@
@uploader.process!("test.jpg")
end

it "should successfully process a multi-page PDF when using RMagick" do
@uploader_class.send :include, CarrierWave::RMagick
@uploader_class.process :convert => 'jpg'
@uploader.cache! File.open(file_path("multi_page.pdf"))
@uploader.process!
context "when using RMagick" do
before do
def @uploader.cover
manipulate! { |frame, index| frame if index.zero? }
end

@uploader_class.send :include, CarrierWave::RMagick
end

after do
@uploader.instance_eval { undef cover }
end

context "with a multi-page PDF" do
before do
@uploader.cache! File.open(file_path("multi_page.pdf"))
end

it "should successfully process" do
@uploader_class.process :convert => 'jpg'
@uploader.process!
end

it "should support page specific transformations" do
@uploader_class.process :cover
@uploader.process!
end
end

context "with a simple image" do
before do
@uploader.cache! File.open(file_path("portrait.jpg"))
end

it "should still allow page specific transformations" do
@uploader_class.process :cover
@uploader.process!
end
end
end

context "with 'enable_processing' set to false" do
Expand Down

0 comments on commit ed1b899

Please sign in to comment.