diff --git a/lib/submissions/generate_result_attachments.rb b/lib/submissions/generate_result_attachments.rb index 60f58f99..2d0e88de 100644 --- a/lib/submissions/generate_result_attachments.rb +++ b/lib/submissions/generate_result_attachments.rb @@ -46,11 +46,14 @@ module Submissions when 'image', 'signature' attachment = submitter.attachments.find { |a| a.uuid == value } - io = StringIO.new(download_supported_image_data(attachment)) - scale = [(area['w'] * width) / attachment.metadata['width'], (area['h'] * height) / attachment.metadata['height']].min + image = Vips::Image.new_from_buffer(attachment.download, '') + image = image.autorot.resize([scale * 4, 1].min) + + io = StringIO.new(image.write_to_buffer('.png')) + canvas.image( io, at: [ @@ -244,7 +247,7 @@ module Submissions page.box.height = attachment.metadata['height'] * scale page.canvas.image( - StringIO.new(download_supported_image_data(attachment)), + StringIO.new(attachment.preview_images.first.download), at: [0, 0], width: page.box.width, height: page.box.height @@ -253,15 +256,6 @@ module Submissions pdf end - def download_supported_image_data(attachment) - if SUPPORTED_IMAGE_TYPES.include?(attachment.content_type) - attachment.download - else - Vips::Image.new_from_buffer(attachment.download, '') - .write_to_buffer('.png') - end - end - def h Rails.application.routes.url_helpers end diff --git a/lib/templates/process_document.rb b/lib/templates/process_document.rb index b7649cce..fd1843b1 100644 --- a/lib/templates/process_document.rb +++ b/lib/templates/process_document.rb @@ -28,7 +28,7 @@ module Templates ActiveStorage::Attachment.where(name: ATTACHMENT_NAME, record: attachment).destroy_all image = Vips::Image.new_from_buffer(binary, '') - image = image.resize(MAX_WIDTH / image.width.to_f) + image = image.autorot.resize(MAX_WIDTH / image.width.to_f) io = StringIO.new(image.write_to_buffer(FORMAT, Q: Q, interlace: true))