Skip to content

Commit

Permalink
Merge pull request #11685 from kepstin/slide-gen-interpolate
Browse files Browse the repository at this point in the history
Recording: Don't use string interpolation when generating commands for slide conversion
  • Loading branch information
ffdixon committed Mar 18, 2021
2 parents 8ccece2 + 7fab16b commit 3fdb60f
Showing 1 changed file with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,31 @@ def self.extract_png_page_from_pdf(page_num, pdf_presentation, png_out, resize =
# In order to handle portrait docs better, scale to a square based on
# the larger of height, width in the resize parameter.
scale = resize.split('x').map(&:to_i).max
BigBlueButton.logger.info("Task: Extracting a page from pdf file as png image")
BigBlueButton.logger.info('Task: Extracting a page from pdf file as png image')
temp_out = "#{File.dirname(png_out)}/temp-#{File.basename(png_out, '.png')}"
command = "pdftocairo -png -f #{page_num} -l #{page_num} -scale-to #{scale} -singlefile #{pdf_presentation} #{temp_out}"
status = BigBlueButton.execute(command, false)
temp_out += ".png"
if status.success? and File.exist?(temp_out)
status = BigBlueButton.execute(
[
'pdftocairo', '-png', '-f', page_num.to_s, '-l', page_num.to_s, '-scale-to', scale.to_s, '-singlefile',
pdf_presentation, temp_out,
],
false
)
temp_out += '.png'
if status.success? && File.exist?(temp_out)
# Resize to the requested size
command = "convert #{temp_out} -resize #{scale}x#{scale} -quality 90 +dither -depth 8 -colors 256 #{png_out}"
status = BigBlueButton.execute(command, false)
status = BigBlueButton.execute(
[
'convert', temp_out, '-resize', "#{scale}x#{scale}", '-quality', '90', '+dither', '-depth', '8', '-colors', '256',
png_out,
],
false
)
end
if !status.success? or !File.exist?(png_out)
if !status.success? || !File.exist?(png_out)
# If page extraction failed, generate a blank white image
command = "convert -size #{resize} xc:white -quality 90 +dither -depth 8 -colors 256 #{png_out}"
BigBlueButton.execute(command)
BigBlueButton.execute(
['convert', '-size', resize, 'xc:white', '-quality', '90', '+dither', '-depth', '8', '-colors', '256', png_out]
)
end
ensure
FileUtils.rm_f(temp_out)
Expand Down

0 comments on commit 3fdb60f

Please sign in to comment.